Wednesday, March 10, 2010

Real-time apply in Data Guard

Real-time apply:

When real-time apply is enabled, the log apply services can apply redo data as it is received, without waiting for the current standby redo log file to be archived.

In this example we are going to use LGWR on the primary for redo transport just to prove that a committed record on the primary without switching a log will show up on the standby. However real-time apply will work with both LGWR and ARCH using SRL's.

- Set up log_archive_dest_2 on the primary with LGWR ASYNC or SYNC

log_archive_dest_2='SERVICE=rhclu2p LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=rhclu2p'

- shutdown and startup the primary or if done dynamically switch a log file
- You will see the following message in the alert log
****************************************************************
LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2
*****************************************************************

- On the standby cancel out of the current managed recovery


SQL>ALTER DATABASER RECOVER MANAGED STANDBY DATABASE CANCEL;

- Place it back in recovery with Real time apply

SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USINGCURRENT
LOGFILE DISCONNECT;

Test Real time apply :

Primary : create a table 'test' and insert a record.

SQL>INSERT INTO test VALUES ( 101, 'testing');
SQL>COMMIT;

Do not switch a log

On the standby :

SQL>SELECT PROCESS, STATUS,SEQUENCE#,BLOCK#,BLOCKS, DELAY_MINS FROM
V$MANAGED_STANDBY;

Notice the block# for the RFS and MRP0 increasing
Cancel out of real time apply and open it in read only mode

SQL>
ALTER DATABASER RECOVER MANAGED STANDBY DATABASE CANCEL;

SQL>ALTER DATABASE OPEN READ ONLY;

SQL>SELECT * FROM.test;

You will see the committed record.

Place the standby back in managed recover mode

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENTLOGFILE DISCONNECT;

( This will take the standby directly from read only mode and place it in managedrecovery mode )

Starting & stopping Managed Recovery (Standby):

Starting & stopping Managed Recovery (Standby):
start
STARTUP MOUNT;
alter database recover managed standby database using current logfile disconnect from session; -- Applies not only completed redo logs, but also redo log currently being copied
or
alter database recover managed standby database disconnect from session; -- Applies completed redo logs

stop
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SHUTDOWN IMMEDIATE;

Monitoring:

SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;

Switchover from primary to standby/ Switchover Primary

1 This process will reverse database roles in a Data Guard setup, i.e. standby database becomes primary.

It’s assumed that:

  1. You already have working Data Guard setup between primary and standby
  2. Archive redo is begin shipped and applied from primary to standby
  3. Archive redo application is up to date between primary & standby

Requirements :

  1. All applications must be shutdown
  2. Switchover must be initiated on primary database before being completed on standby database
  3. The primary database must be open, the standby database must be mounted and in managed recovery mode.
Note
When you perform a switchover the controlfile type is converted in-place, i.e. the primary controlfile becomes a standby controlfile and vice-versa. You must be CAREFUL which database you are working on…..

On the STANDBY database

1. Check archive_lag_target

SQL> show parameters lag

NAME TYPE VALUE ———————————— ———– —————————-
archive_lag_target integer 0

If non-zero set to zero using

SQL> alter system set archive_lag_target=0 scope=both;

On the PRIMARY database

1. Shutdown RAC databases

(RAC environment only) Shutdown all but one of the primary database instances.

2. Verify it is possible to switchover

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS

——————

SESSIONS ACTIVE

Switchover requires that there be only one active session (the one performing the switchover).

Documentation states the above query should return “TO STANDBY” for switchover to succeed but it – always returns “SESSIONS ACTIVE” because of the one active session – Problemo!!

The key point is to make sure there is only one user connected – SYS – check V$SESSION

3. Initiate the switchover

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;

Database altered.

This converts the primary database to standby. Current controlfile is backed up to trace should you need to reverse the switchover. At this stage we temporarily have two standby databases…

4. Shutdown, restart and mount as standby

SQL> SHUTDOWN NORMAL;

ORA-01507: database not mounted <= This can be ignored

ORACLE instance shut down.

SQL> STARTUP NOMOUNT;
ORACLE instance started.
Total System Global Area 920912008 bytes
Fixed Size 711896 bytes
Variable Size 285212672 bytes
Database Buffers 111554492 bytes
Redo Buffers 811008 bytes

SQL> ALTER DATABASE MOUNT STANDBY DATABASE;

Database altered.

5. Verify switchover status

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS

——————

SESSIONS ACTIVE

According to documentation this should return “SWITCHOVER PENDING”, same catch as before, there has to be one session active to do the switchover.

On the STANDBY database

6. Switch standby database to primary

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY ;

Database altered.

7. Shutdown and restart the new primary database

SQL> SHUTDOWN

ORA-01507: database not mounted <= This can be ignored

ORACLE instance shut down.

SQL> STARTUP
ORACLE instance started.
Total System Global Area 920912008 bytes
Fixed Size 711896 bytes
Variable Size 285212672 bytes
Database Buffers 111554492 bytes

Redo Buffers 811008 bytes
Database mounted.
Database opened.

The database is now the primary database.

On the STANDBY database (the original primary)

8. Start managed recovery and log apply services and set archive lag target

SQL> ALTER SYSTEM SET ARCHIVE_LAG_TARGET=900 SCOPE=BOTH;

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

On the PRIMARY database (the original standby)

9. Begin archiving logs

SQL> ALTER SYSTEM ARCHIVE LOG START;

System altered.

SQL> ALTER SYSTEM SWITCH LOGFILE;

System altered.


On BOTH databases

10. Check the alert logs to make sure archived redo is being sent and received

The primary alert log should look like this

ARC1: Evaluating archive log 3 thread 1 sequence 30

ARC1: Archive destination LOG_ARCHIVE_DEST_2: Previously completed

ARC1: Beginning to archive log 3 thread 1 sequence 30

Creating archive destination LOG_ARCHIVE_DEST_1: ‘/u01/app/oracle/archive/arch/DATAGD_1_30.arc’

ARC1: Completed archiving log 3 thread 1 sequence 30

The standby alert log should look like this

Media Recovery Waiting for thread 1 seq# 30 (in transit)

Fri Sep 3 10:12:14 2004

Media Recovery Log ‘/u01/app/oracle/archive/arch/DATAGD_1_30.arc






What mode should I keep the standby database ????

If you keep a standby database in Read Only mode then it will not apply archivals.

Quote:

While a standby database is open for read-only or read/write access, it does not apply redo data received from the primary database, thus it is not kept transactionally consistent with the primary database.
When a physical standby database is open, redo data from the primary database is received by the standby database, but the log files are not applied. At some point, you need to resume Redo Apply on the standby database, and apply the archived redo log files to resynchronize the standby database with the primary database.Because of the additional time required to apply any accumulated archived redo log files, having a standby database open for read-only access can increase the time required to complete failovers or switchovers

To open a standby database for read-only access when it is currently performing Redo Apply:

1. Cancel Redo Apply:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
2. Open the database for read-only access:
SQL> ALTER DATABASE OPEN;
You do not need to shut down the instance to open it for read-only access.


To change the standby database from being open for read-only access to performing Redo Apply:
1. Terminate all active user sessions on the standby database if there.
2. Restart Redo Apply. To start Redo Apply, issue the following statement:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

To enable real-time apply, include the USING CURRENT LOGFILE clause:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE;

You do not need to shut down the instance to start either of these apply modes .


Minimum Archive Log Necessary to Restart Capture for 10GR2 and 11GR1

----- Begin ckpt_scn_query_10GR2_11GR1.sql -----

prompt ++ Minimum Archive Log Necessary to Restart Capture ++

prompt Note: This query is valid for databases where the capture processes exist for the same source database.

prompt

set serveroutput on

DECLARE

hScn number := 0;

lScn number := 0;

sScn number;

ascn number;

alog varchar2(1000);

begin

select min(start_scn), min(applied_scn) into sScn, ascn

from dba_capture;

DBMS_OUTPUT.ENABLE(2000);

for cr in (select distinct(a.ckpt_scn)

from system.logmnr_restart_ckpt$ a

where a.ckpt_scn <= ascn and a.valid = 1

and exists (select * from system.logmnr_log$ l

where a.ckpt_scn between l.first_change# and l.next_change#)

order by a.ckpt_scn desc)

loop

if (hScn = 0) then

hScn := cr.ckpt_scn;

else

lScn := cr.ckpt_scn;

exit;

end if;

end loop;

if lScn = 0 then

lScn := sScn;

end if;

dbms_output.put_line('Capture will restart from SCN ' || lScn ||' in the following file:');

for cr in (select name, first_time

from DBA_REGISTERED_ARCHIVED_LOG

where lScn between first_scn and next_scn order by thread#)

loop

dbms_output.put_line(cr.name||' ('||cr.first_time||')');

end loop;

end;

/

----- End ckpt_scn_query_10GR2_11GR1.sql -----

Tuesday, March 9, 2010

Expanding Linux Partitions with LVM

What is LVM

The Logical Volume Manager (LVM) enables you to resize your partitions without having to modify the partition tables on your hard disk. LVM becomes useful when you are running out of disk space and instead of reinstalling your system on a larger driver, you can simpy expand your existing partiton scheme, without loosing any data on it.


Why this article

I'll try to show you, plain and simple, as less pain as possible howto setup and use LVM on your system. Since the official manuals and HOWTOs are *very* long, I'll make it quick and simple. Well, at leas I'll try to ;-)


LVM Terms

Once you understand the terms, setting up and managing LVM will be a "peace of cake" for you. So it's important for you that you know what this terms means. If you won't understand the terms, than you might brake your system badly. This is the first-hand info, It happend to me on the RHCE exam. I broke the system in a way that was completely unusefull :) Lucky for me this was the only thing that i didn't manage to work, so i passed anyways ;-)


  • physical volume: A physical volume (PV) is another name for a regular physical disk partition that is used or will be used by LVM.
  • logical volume: The equivalent of a disk partition in a non-LVM system. The LV is visible as a standard block device; as such the LV can contain a file system (eg. /home).
  • volume group: The Volume Group is the highest level abstraction used within the LVM. It gathers together a collection of Logical Volumes and Physical Volumes into one administrative unit.
  • physical extent: Each physical volume is divided chunks of data, known as physical extents, these extents have the same size as the logical extents for thevolume group.
  • logical extent: Each logical volume is split into chunks of data, known as logicalextents. The extent size is the same for all logical volumes in the volume group.


The Scenario

  • In the first scenario we will be creating LVM's on already installed system. We will expand our /home folder with brand new 4GB hard disk added.
  • in the second scenario will setup LVM partitions at install time and expand it later, with 4GB hard disk, that we will add.


The quick list

After understanding the LVM concept, keep this in mind and you'll be fine.


Adding a Logical Volume

  • backup
  • fdisk, and change the partition system id to 8e (Linux LVM)
  • pvcreate (Create Physical Volume)
  • vgcreate (Create Volume group)
  • lvcreate (to assign LV size)
  • mkfs -j (reformat the filesystem)
  • fstab (edit to suite your needs)
  • mount (remount the new volume)


Extending a Logical volume

  • backup
  • umount
  • fdisk, and change the partition system id to 8e (Linux LVM)
  • pvcreate (Create Physical Volume)
  • vgextend (Extend the Volume Group)
  • lvextend (Extend the LV)
  • mount
  • ext2online (Expand volume to the actual size)
  • umount
  • e2fsck -f (check the filesystem)
  • mount (remount the new volume)


Removing Logical Volumes

  • backup (do you need data on this volume?)
  • umount (umount volume)
  • lvremove (remove Logical Volume)


Creating and adding LVM

Let's get to work. First, we will setup LVM on already installed system, than we will setup LVM at install time and expend it later on.


On already installed and running system

In this scenario we have /home partition on a seperate partition and ext3 filesystem on it. We backup the partition, convert the parttion to LVM partition type and expand it with brand new 4GB hard disk added to our system.


First thing that you need to think of when expanding is backup of your partition/volumethat you will expand, because you will loose all your data on it when finished. We're going to backup our home folder with tar, since we want the permissions to be kept as they are. This is done with the following command

[root@localhost ~]# tar cvfz backup-home.tar.gz /home
tar: Removing leading `/' from member names
/home/
/home/lost+found/
/home/anze/
/home/anze/.bashrc
/home/anze/.bash_logout
/home/anze/.gtkrc
/home/anze/.bash_profile
[root@localhost ~]#

Ok, just to make you feel better, check the content of the tar file, just tu make sure...

[root@localhost ~]# tar -tvf backup-home.tar.gz
drwxr-xr-x root/root 0 2005-11-07 10:25:33 home/
drwx------ root/root 0 2005-11-07 10:43:49 home/lost+found/
drwxr-xr-x anze/anze 0 2005-11-07 10:25:33 home/anze/
-rw-r--r-- anze/anze 124 2005-11-07 10:25:33 home/anze/.bashrc
-rw-r--r-- anze/anze 24 2005-11-07 10:25:33 home/anze/.bash_logout
-rw-r--r-- anze/anze 120 2005-11-07 10:25:33 home/anze/.gtkrc
-rw-r--r-- anze/anze 191 2005-11-07 10:25:33 home/anze/.bash_profile
[root@localhost ~]#

Next, change the partition system type with fdisk. This is done as follows:

[root@localhost ~]# fdisk /dev/hda


Command (m for help): p

Disk /dev/hda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 268 2048287+ 83 Linux
/dev/hda3 269 333 522112+ 82 Linux swap / Solaris
/dev/hda4 334 522 1518142+ 5 Extended
/dev/hda5 334 522 1518111 83 Linux

Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)


Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]#


Now that we have everything set up for the merge, let's create the physical volume from home partition

[root@localhost ~]# pvcreate /dev/hda5
Physical volume "/dev/hda5" successfully created
[root@localhost ~]#

...and physical volume on the new hard disk:

[root@localhost ~]# pvcreate /dev/hdb
Physical volume "/dev/hdb" successfully created
[root@localhost ~]#

Now, create the Volume group named VolGroup00 and include the home partition and the new disk partition into this group:

[root@localhost ~]# vgcreate VolGroup00 /dev/hda5 /dev/hdb
Volume group "VolGroup00" successfully created

Now that this is done, let's check the volume groups:

[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 5.44 GB
PE Size 4.00 MB
Total PE 1393
Alloc PE / Size 0 / 0
Free PE / Size 1393 / 5.44 GB
VG UUID qPNDwe-Ma0K-PNJC-6zKS-gvCi-4H3P-1GYykh

So, everything is fine, as you can see we have 5.44GB (1393 PE's) free space to create a logical volume

[root@localhost ~]# lvcreate -l 1393 VolGroup00
Logical volume "lvol0" created
[root@localhost ~]#

And to see the results:

[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/lvol0
VG Name VolGroup00
LV UUID 0rGNBf-dcaW-bS1G-JEw8-QvlU-KIGT-AfusDb
LV Write Access read/write
LV Status available
# open 0
LV Size 5.44 GB
Current LE 1393
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0

[root@localhost ~]#

Done. Next, let's edit our /etc/fstab file so it will be able to mount /home from a newlogical volume:

This is my case:

[root@localhost ~]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
/dev/devpts /dev/pts devpts gid=5,mode=620 0 0
/dev/shm /dev/shm tmpfs defaults 0 0
/dev/VolGroup00/lvol0 /home ext3 defaults 0 0
/dev/proc /proc proc defaults 0 0
/dev/sys /sys sysfs defaults 0 0
LABEL=SWAP-hda3 swap swap defaults 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0
/dev/hdc /media/cdrom auto pamconsole,exec,noauto,managed 0 0
[root@localhost ~]#

Create the file system on the logical volume:

[root@localhost ~]# mkfs -j /dev/VolGroup00/lvol0
mke2fs 1.37 (21-Mar-2005)

Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
713856 inodes, 1426432 blocks
71321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1463812096

44 block groups
32768 blocks per group, 32768 fragments per group
16224 inodes per group

Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#

And we are done. Mount it, just to make sure, you have the correct entries in the /etc/fstab file

[root@localhost ~]# mount /home

If everything configured correctly, the /home is mounted and you can check the capacity with:

[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/hda2 1.9G 603M 1.3G 33% /
/dev/hda1 99M 9.3M 85M 10% /boot
/dev/shm 163M 0 163M 0% /dev/shm
/dev/mapper/VolGroup00-lvol0
5.4G 43M 5.1G 1% /home
[root@localhost ~]#

At this point you are ready to restore your home folder files and you're all set.


At install time

First, let's create basic partitions. I have a 4Gb disk, that I will configure as follows:

  • 100Mb ext3 partition for /boot
  • 512Mb swap partition
  • 2GB ext3 partition for /
  • the rest of free space will be used for /home

Since I'm sure you already know how to do the "basic" part of partitioning I'll show you the LVM part, It's really easy. All you have to do is select "New" partition and under "File System Type" choose "physical volume (LVM). Make sure you select to fill the whole rest of free space for size.

The setup part looks like this:

Image:lvm1a.JPG


And your partition setup end up looking like this

Image:lvm2a.JPG

Now that you've define the physical volume it's time to define what will this partition hold. Select the "LVM" button. The new windows opens and you can choose from a various things.

  • Volume Group Name: We can leave this as is (VolGroup00). If you were up to define more logical volume names, you would use VolGroup01 for the second group, VolGroup02 for the third group etc...
  • Physical Extend: If you forgot what this is, scrool up. It's important that you know what you are doing.
  • Logical Volumes: here we will define a new logical volume for /homefolder/partition. Select "Add" button and configure it as shown below:


Image:lvm3a.JPG


As you can see the mount point is /home, file system type is ext3, Logical volume name is LogVol00, and the size of this volume is 1440Mb.

Your partitions will end up looking like this:

Image:lvm4a.JPG


This is the end of LVM setup part. Next, install the packages that you like and finish the installation. After the reboot, you can check your partitions to see that your /home is actually made of LVM.


Extending LVM partition

Fedora Core 4 comes with a LVM tool called system-config-lvm. It's a GUI for managing LVM's. You can start it up by either selecting it from the menu bar or from the console with the command

[root@localhost ~]# system-config-lvm

The GUI looks really nice and it provides us with all the information that you need. The only bad thing here is that the tool is not complete yet, so we won't be using it. Instead, we will be expanding our partitions in console.


Ok, first we need to unmount home folders, we can't be working while volume is mounted.

[root@localhost ~]# umount /home/

Now, let's check the existing physical volumes with the following command

[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/hda5
VG Name VolGroup00
PV Size 1.44 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 46
Free PE 1
Allocated PE 45
PV UUID auQ2kD-GuHQ-6feE-nSr9-cA0A-dGbD-CrHZhg

[root@localhost ~]#

Ok, as you can see, we have one Physical volume that is made from the /dev/hda5 partition, and we have a Volume Group name for it, it's VolGroup00. You can also see the size of the physical volume etc...


Let's prepare our new disk to be able to join our existing VG. First step is to create one (or more if you like) partition(s) on the new disk and we have to make sure it's labeled correct. For our example we'll create one partition, type LVM and we will use the whole disk size. Let's assume the second disk is secondary master (/dev/hdb) so start fdisk with:

[root@localhost ~]# fdisk /dev/hdb

Create new, primary partition that will contain all the disk space:

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-8322, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-8322, default 8322):
Using default value 8322


Command (m for help): p


Disk /dev/hdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes


Device Boot Start End Blocks Id System
/dev/hdb1 1 8322 4194256+ 83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Note that we changed the partition system ID to Linux LVM. I've chosen the longer way, just to make you see how It's partitioning part done. Because if you plan to have the whole disk space for LVM, you can skip this part of creating partitions, instead, you can just make the whole disk physical volume by typing

[root@localhost ~]# pvcreate /dev/hdb
Physical volume "/dev/hdb" successfully created


Let's check again our PV's with the pvdisplay command again, and you should see something like this:

[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/hda5
VG Name VolGroup00
PV Size 1.44 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 46
Free PE 1
Allocated PE 45
PV UUID auQ2kD-GuHQ-6feE-nSr9-cA0A-dGbD-CrHZhg

--- Physical volume ---
PV Name /dev/hdb
VG Name VolGroup00
PV Size 3.97 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 127
Free PE 127
Allocated PE 0
PV UUID 6TvkYu-sY2K-tIsj-aXZh-KLPb-81Ox-oPIFyO

As you can see we now have two Physical volumes that we will merge into one VG in the next step.

Extend the VG to include the new hard drive or partitions that you've created. In our case, we will add /dev/hdb to the /home VG. You would run the following command:

[root@localhost ~]# vgextend VolGroup00 /dev/hdb
Volume group "VolGroup00" successfully extended

Now let's see the VG stats again:

[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 5.41 GB
PE Size 32.00 MB
Total PE 173
Alloc PE / Size 45 / 1.41 GB
Free PE / Size 128 / 4.00 GB
VG UUID P9fvht-mGVG-ksd7-vyhf-yDfi-lhC9-zrNSEw

[root@localhost ~]#

No surprises here, we see that the total size of VG, that we can use for our /home partition can be 5.41GB (128 PE's free).

At this point we have only extend the VG and not the actual size of LV! The lvextend command will configure LVs in KB, MB, GB, or even TB. For example, you could get the same result with the following command:

[root@localhost ~]# lvextend -L5410M /dev/VolGroup00/LogVol00
Rounding up size to full physical extent 5.31 GB
Extending logical volume LogVol00 to 5.31 GB
Logical volume LogVol00 successfully resized

Now, mount the extended volume back

[root@localhost ~]# mount /home

Use the ext2online tool to resize the volume to the actual size

[root@localhost ~]# ext2online /dev/VolGroup00/LogVol00

Let's make sure our extended filesystem is healthy, so we need to unmount it and check it with fsck tool:

[root@localhost ~]# umount /home
[root@localhost ~]# e2fsck -f /dev/VolGroup00/LogVol00
e2fsck 1.38 (30-Jun-2005)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VolGroup00/LogVol00: 20/334464 files (5.0% non-contiguous), 14806/393216 blocks

Mount /home again and check the size

[root@localhost ~]# mount /home
[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/hda2 1.9G 600M 1.3G 33% /
/dev/hda1 99M 9.3M 85M 10% /boot
/dev/shm 163M 0 163M 0% /dev/shm
/dev/mapper/VolGroup00-LogVol00
5.4G 43M 5.1G 1% /home


Removing Logical Volumes

Removing an existing LV is simple. The command to accomplish that is lvremove.

Make sure you save any data in directories that are mounted on the LV.

Unmount any directories associated with the LV, otherwise you won't be able to delete them.

[root@localhost ~]# umount /dev/Volume01/LogVol01


Next, apply the lvremove command to the LV:

[root@localhost ~]# lvremove /dev/Volume01/LogVol01

Done. You should now have the PEs from this LV free for use in other LVs.