Monday, October 22, 2012

PuTTY X11 proxy: wrong authorisation protocol attempted Error: Can't open display: localhost:X.Y

This site helped with the solution:

http://froebe.net/blog/2008/11/14/getting-xlib-putty-x11-proxy-wrong-authentication-protocol-attempted-i-have-the-answer/

This site helped with configuring Xming:

http://www.math.umn.edu/systems_guide/putty_xwin32.html

Here's what I did (this assumes you have Xming installed and configured):

After installing Xming on a Windows box, I installed PuTTY.  I configured my PuTTY session for X11 forwarding as follows:

1. Start PuTTY

2. Enter a name or IP address in the Host Name (or IP address) box and for Connection type, select SSH

3. Save the session

4. In the Category section, expand Connection then SSH, then X11

5. On the Options controlling SSH X11 forwarding screen, check Enable X11 forwarding and MIT-Magic-Cookie-1

6. From the Category section on the left, click Session and then click Save in the Basic options for Your PuTTY session section

7. Start an Xming session, followed by an SSH session from PuTTY

8. From your newly opened SSH session, type xclock

9. An xwindow clock will appear on your Windows server

10. Now su - oracle

11. Attempt the same by typing xclock and you'll see an error such as this:
PuTTY X11 proxy: wrong authorisation protocol attempted Error: Can't open display: localhost:11.0

12. Open another PuTTY session and type the following:
# xauth list
localhost.localdomain/unix:0  MIT-MAGIC-COOKIE-1  1425043ba52e4f50f597c83d434baf82

13. In your oracle session, type the following:
$ xauth add localhost:0  MIT-MAGIC-COOKIE-1  1425043ba52e4f50f597c83d434baf82

14. Export your display to your Windows box:
$ export DISPLAY=192.168.10.120
$ export DISPLAY=localhost:10.0
Thanks for the correction to Anonymous posted January 25, 2013.

15. Run xclock, and you should see the clock on your Windows box
Running yum install <package_name> gives "The requested URL returned error: 404"

On a recently created CentOS 6.2 x64 VM, I tried to install some packages such as compat-libstdc++-33.x86_64 but when I ran the command:

# yum install compat-libstdc++-33.x86_64

I got the following errors:

...
...
http://mirror.atlanticmetro.net/centos/6.2/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404"
Trying other mirror.
http://mirror.clarkson.edu/centos/6.2/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404"
Trying other mirror.
http://mirror.cs.vt.edu/pub/CentOS/6.2/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404"
Trying other mirror.
...
...
Trying other mirror.
http://pubmirrors.reflected.net/centos/6.2/os/x86_64/Packages/elfutils-libelf-devel-0.152-1.el6.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404"
Trying other mirror.


Error Downloading Packages:
  elfutils-libelf-devel-0.152-1.el6.x86_64: failure: Packages/elfutils-libelf-devel-0.152-1.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.

To resolve the issue, I ran the following command:

# yum clean all
Loaded plugins: fastestmirror, presto, refresh-packagekit
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
0 delta-package files removed, by presto
 
I was then able to install the required package:

# yum install compat-libstdc++-33.x86_64
Loaded plugins: fastestmirror, presto, refresh-packagekit
Determining fastest mirrors
 * base: mirror.flhsi.com
 * extras: mirrors.loosefoot.com
 * updates: mirror.nwresd.org
base                                                     | 3.7 kB     00:00
base/primary_db                                          | 4.5 MB     00:00
extras                                                   | 3.5 kB     00:00
extras/primary_db                                        | 8.9 kB     00:00
updates                                                  | 3.5 kB     00:00
updates/primary_db                                       | 3.4 MB     00:09
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package compat-libstdc++-33.x86_64 0:3.2.3-69.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                    Arch          Version             Repository   Size
================================================================================
Installing:
 compat-libstdc++-33        x86_64        3.2.3-69.el6        base        183 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 183 k
Installed size: 806 k
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 183 k
compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm              | 183 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : compat-libstdc++-33-3.2.3-69.el6.x86_64                      1/1

Installed:
  compat-libstdc++-33.x86_64 0:3.2.3-69.el6

Complete!

Friday, October 5, 2012

Automated Process to Apply Oracle PSU for Multiple Instances (Oracle 10g)

Assumes that there is more than one instance of an Oracle database in a Streams environment.

Assumes that a patch is to be applied along with a PSU.

Assumes that the listeners have been stopped.

Assumes that all relevant patches have been copied to $ORACLE_HOME/patches.

Should also work for 11g environments.

The operator is asked to run the script in the following order:


Apply the Patch (e.g. Patch ID 11724977)
1. Shutdown all database instances 
   $ sh patch_it.sh shutdown

2. Apply the patch 
   $ sh patch_it.sh patch_apply

3. Start up the database instances 
   $ sh patch_it.sh startup 


Apply the PSU 
1. Stop streams (note that for this case, the PSU does not require that the instances be shutdown). 
   $ sh patch_it.sh stop_streams 

2. Apply PSU
   $ sh patch_it.sh psu_apply 

3. Start streams 
   $ sh patch_it.sh start_streams 

Post-Installation Procedure
1. Check that the patch has been installed (this verifies that patch 11724977 has been applied) 
   $ sh patch_it.sh patch_check 

Back-out Procedure
1. Shutdown all database instances 
   $ sh patch_it.sh shutdown



2. Rollback the patch (Patch ID 11724977) 
   $ sh patch_it.sh patch_rollback

3. Start up all instances 
   $ sh patch_it.sh startup

4. Stop streams 
   $ sh patch_it.sh stop_streams

5. Rollback the PSU 
   $ sh patch_it.sh psu_rollback 


patch_it.sh Shell Script

#!/bin/bash

# Shuts down all streams processes
function stop_streams {
   echo
   echo "Shutting Down Streams"
   echo
   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' @stop_streams.sql << EOD
EOD
   done
}
# Starts up all streams processes
function start_streams {
   echo
   echo "Start Up Streams"
   echo
   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' @start_streams.sql << EOD
EOD
   done
}

# Shuts down all databases
function shutdown {
   echo
   echo "Shutdown databases"
   echo


   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' << EOD
      shutdown immediate
EOD
      done

   echo
   echo "All databases have been shutdown"
   echo
}

# Starts up all databases
function startup {
   echo
   echo "Startup databases"
   echo

   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' << EOD
      startup
EOD
   done

   echo
   echo "All databases have been started"
   echo
}

# Starts up all databases in UPGRADE mode
function startup_upgrade {
   echo
   echo "Startup databases - upgrade"
   echo

   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' << EOD
      startup upgrade
      spool patch_$NAME.log
      @?/rdbms/admin/catupgrd.sql
      spool off
EOD
   done

   echo
   echo "All databases have been started in upgrade mode"
   echo
}

# Run utlrp
function run_utlrp {
   echo
   echo "Running utlrp..."
   echo

   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' << EOD
      shutdown immediate
EOD
   done

   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' << EOD
      startup
      @?/rdbms/admin/utlrp.sql
EOD
   done

   echo
   echo "All databases have been upgraded"
   echo

}

# Check database registy
function check_db_registry {
   echo
   echo "Checking database registry..."
   echo

   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' << EOD
      @rmOCM.sql
      SELECT COMP_NAME, VERSION, STATUS FROM SYS.DBA_REGISTRY;
EOD
   done

}

# Checks opatch functionality
function patch_check {
   echo "Checking OPatch Functionality"

   cd $ORACLE_HOME/patches
   $OPATCH prereq CheckConflictAgainstOHWithDetail -jre $ORACLE_HOME/$JRE -phBaseDir ./$PATCH_ID -invPtrLoc $ORACLE_HOME/oraInst.loc || { echo "opatch check failed"; exit 1; }
}

# Applies patch
function patch_apply {
   echo "Applying Patch $PATCH_ID"
   cd $ORACLE_HOME/patches/$PATCH_ID
   $OPATCH apply -jre $ORACLE_HOME/$JRE -invPtrLoc $ORACLE_HOME/oraInst.loc || { echo "opatch apply $PATCH_ID failed"; exit 1; }
}

# Applies psu_apply
function psu_apply {
   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' << EOD
      @?/rdbms/admin/catbundle.sql psu apply
EOD
   done
}

# Rolls back patch
function patch_rollback {
   echo "Rolling back patch"
   cd $ORACLE_HOME/patches/$PATCH_ID
   $OPATCH rollback -id $PATCH_ID -jre $ORACLE_HOME/$JRE -invPtrLoc $ORACLE_HOME/oraInst.loc || { echo "opatch rollback $PATCH_ID failed"; exit 1; }
     
}

# Rollback psu_apply
function psu_rollback {
   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      NAME=`echo $NAME | tr '[:lower:]' '[:upper:]'`
      sqlplus '/ as sysdba' << EOD
      @?/rdbms/admin/catbundle_PSU_${NAME}_ROLLBACK.sql

EOD
   done
}

function downgrade_db {
   cp -rfp $ORACLE_HOME/rdbms/admin/catrelod.sql .
   cp -rfp $ORACLE_HOME/network/admin .
   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' <<EOD
      startup downgrade
      SPOOL downgrade_$NAME.out
      @?/rdbms/admin/catdwgrd.sql
      SPOOL OFF
      SHUTDOWN IMMEDIATE
EOD
   done
}

function downgrade_cat {
   cp -rfp catrelod.sql $ORACLE_HOME/rdbms/admin/
   cp -rfp admin $ORACLE_HOME/network/
   for NAME in $NAME_LIST
   do
      export ORACLE_SID=$NAME
      sqlplus '/ as sysdba' <<EOD
      startup downgrade
      SPOOL catrelod_$NAME.out
      @?/rdbms/admin/catrelod.sql
      SPOOL OFF
      SHUTDOWN IMMEDIATE
EOD
   done
}

##########################
# main                   #
##########################

# Must NOT be run as root
if [ "$(id -n -u)" != "oracle" ]
then
   echo "This script must be run as oracle" 1>&2
   exit 1
fi

ORACLE_HOME=/opt/app/oracle/product/10.2.0/db_1
OPATCH=$ORACLE_HOME/patches/OPatch/opatch
JRE=`ls -l $ORACLE_HOME|grep jre1|awk -F" " '{ print $9 }'`
#
# Change to relevant Patch ID
#
PATCH_ID=11724962
HOSTNAME=`hostname -f | awk -F . '{print $1}'`
# Hostname is in the form of servername-1a.<domain_name>/servername-2a.<domain_name>
# etc...  Matching on 1, we can determine if we are on servername-1 or servername-4
match="1"

if [[ "$HOSTNAME" =~ "${match}" ]]; then
     NAME_LIST="dbwhrs01 dbprod01 dbweb01"
     export NAME_LIST
  else
     NAME_LIST="dbwhrs02 dbprod02 dbweb02"
     export NAME_LIST
fi

case "$1" in
'startup')
   startup
;;
'startup_upgrade')
   startup_upgrade
;;
'run_utlrp')
   run_utlrp
;;
'check_db_registry')
   check_db_registry
;;
'shutdown')
   shutdown
;;
'patch_check')
   patch_check
;;
'patch_apply')
   patch_apply
;;
'psu_apply')
   psu_apply
;;
'patch_rollback')
   patch_rollback
;;
'psu_rollback')
   psu_rollback
;;
'start_streams')
   start_streams
;;
'stop_streams')
   stop_streams
;;
'downgrade_db')
   downgrade_db
;;
'downgrade_cat')
   downgrade_cat
;;
*)
   echo "Usage: $0 [startup|shutdown|patch_check|patch_apply|psu_apply|startup_upgrade|run_utlrp|check_db_registry|stop_streams|start_streams|patch_rollback|psu_rollback|downgrade_db|downgrade_cat]"
esac

stop_streams.sql Script
set serveroutput on size 1000000
declare

v_apply_name varchar2(100) := '';
v_capture_name varchar2(100) := '';
v_propagation_name varchar2(100) := '';

begin

   select apply_name into v_apply_name from dba_apply;
   select capture_name into v_capture_name from dba_capture;
   select propagation_name into v_propagation_name from dba_propagation;

   begin
      DBMS_APPLY_ADM.STOP_APPLY(apply_name => v_apply_name);
   exception
   when others then
      null;
   end;

   begin
      DBMS_CAPTURE_ADM.STOP_CAPTURE(capture_name => v_capture_name);
   exception
   when others then
      null;
   end;

   begin
      DBMS_PROPAGATION_ADM.STOP_PROPAGATION(v_propagation_name);
   exception
   when others then
      null;
   end;
end;
/

start_streams.sql Script
set serveroutput on size 1000000
declare

v_apply_name varchar2(100) := '';
v_capture_name varchar2(100) := '';
v_propagation_name varchar2(100) := '';

begin

   select apply_name into v_apply_name from dba_apply;
   select capture_name into v_capture_name from dba_capture;
   select propagation_name into v_propagation_name from dba_propagation;

   begin
      DBMS_APPLY_ADM.START_APPLY( apply_name => v_apply_name);
   exception
   when others then
      null;
   end;

   begin
      DBMS_CAPTURE_ADM.START_CAPTURE(capture_name => v_capture_name);
   exception
   when others then
      null;
   end;

   begin
      DBMS_PROPAGATION_ADM.START_PROPAGATION(v_propagation_name);
   exception
   when others then
      null;
   end;
end;
/
rmOCM.sql Script
Our site does not allow OCM component to be installed, hence it needs to be removed.

-- remove old dba jobs, if exists
DECLARE
job_num NUMBER;
CURSOR job_cursor is
    SELECT job
    FROM dba_jobs
    WHERE schema_user = 'ORACLE_OCM'
    AND (what like 'ORACLE_OCM.MGMT_CONFIG.%'
     OR what like 'ORACLE_OCM.MGMT_DB_LL_METRICS.%');
BEGIN
   FOR r in job_cursor LOOP
     sys.DBMS_IJOB.REMOVE(r.job);
     COMMIT;
   END LOOP;
   EXCEPTION
     WHEN OTHERS THEN
       -- ignore any exception
       null;
END;
/

#Rem stop the job
BEGIN
   BEGIN
     -- call to stop the job
     ORACLE_OCM.MGMT_CONFIG.stop_job;  
   EXCEPTION
     WHEN OTHERS THEN
       -- ignore any exception
       null;
  END;
END;
/

-- disable jobs

exec dbms_scheduler.disable('ORACLE_OCM.MGMT_STATS_CONFIG_JOB');
exec dbms_scheduler.disable('ORACLE_OCM.MGMT_CONFIG_JOB');

-- drop user ORACLE_OCM

drop user ORACLE_OCM cascade;

Thursday, October 4, 2012

My first PostgreSQL stored function...

Goal
------
Have the following table:
ld_operatingsystem

        Column        |            Type             | Modifiers
----------------------+-----------------------------+-----------
 computer_idn         | numeric                     |
 operating_system_idn | numeric                     |
 ostype               | character varying(255)      |
 version              | character varying(255)      |
 laststartuptime      | timestamp without time zone |
 facility_id          | numeric                     |
 suitename            | character varying(255)      |

I need to update the suitename column so that it is composed of the concatenation of the ostype and version columns.

Start a psql session and paste the function:

create or replace function u_ld_tbl() returns void as $$

declare

   userRecord record;

begin

   for userRecord IN
      select computer_idn, operating_system_idn, ostype, version from ld_operatingsystem
   loop
      update ld_operatingsystem
      set suitename = userRecord.ostype||' '||userRecord.version
      where computer_idn = userRecord.computer_idn
      and operating_system_idn = userRecord.operating_system_idn;

      raise notice 'Updated %, % ', userRecord.computer_idn, userRecord.operating_system_idn;
   end loop;

   return;
end;

$$ language plpgsql;

The function can be invoked from psql as follows:

select u_ld_tbl();
NOTICE:  Updated 31, 19
NOTICE:  Updated 1, 1
NOTICE:  Updated 4, 7
...
...
...
NOTICE:  Updated 53, 37
NOTICE:  Updated 54, 38
NOTICE:  Updated 55, 39
 u_ld_tbl
----------

(1 row)


Thursday, April 12, 2012

Installing mapserv on CentOS 6

Required
--------
Do this as root.
# yum install libpng libpng-devel
# yum install freetype
# yum install gd gd-devel
# yum install zlib
# yum install giflib-devel

Recommended
-----------
If gcc not installed, install it so that proj can compile.  Do this as root.
# yum install gcc

# http://download.osgeo.org/proj/proj-4.8.0.tar.gz
# gunzip, then untar, create /opt/proj-4.8.0
# cd /opt/proj-4.8.0
# ./configure
# make
# make check
# make install

# yum install libcurl

As root Install of OGR and GDAL
-----------------------
# yum install http://elgis.argeo.org/repos/5/elgis-release-5-5_0.noarch.rpm

# yum install agg agg-devel

# yum install readline-devel
# yum install zlib-devel
# yum install libxml2-devel
# yum install geos-devel
# yum install gcc-c++
# yum install curl-devel

Optional
--------
# yum install libtiff
# yum install libgeotiff
# yum install libjpeg
# yum install geos
# yum install libxml2

As root Install PostgreSQL
------------------
# tar xvf postgresql-9.1.3.tar.gz
# cd /opt/postgresql-9.3.1

# cd /usr/lib64
# ln -s /lib64/libreadline.so.6.0 libreadline.so.6.0
# ./configure
# gmake
# gmake install
# adduser postgres
# mkdir /usr/local/pgsql/data
# chown postgres /usr/local/pgsql/data
# su - postgres
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &


As root Install geos-3.3.3
-------------------
# cd /opt/geos-3.3.3
# ./configure
# make
# make install

As root Install gdal-1.9.0
------------------
# cd /opt/gdal-1.9.0
# ./configure
# make
# make install

As root and postgres Install PostGIS
------------------------------
Download postgis-x.y.z.tar.gz

# chown postgres: -R /opt/postgis-2.0.0
# su - postgres
$ cd /opt/postgis-2.0.0
$ ./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --libdir=/usr/lib64
$ make

make check will throw errors about permissions 
----------------------------------------------
change perms to 777, re-run make check then change perms back
-------------------------------------------------------------
$ make check
$ make install

As root Install gd (even though installed w/yum)
----------------------------------------
# cd /opt/gd
# ./configure
# make
# make install

As root Install mapserver-6.0.2
-----------------------
# ./configure     --with-ogr=/usr/local/bin/gdal-config \
                --with-gdal=/usr/local/bin/gdal-config \
                --with-httpd=/usr/sbin/httpd \
                --with-wfsclient \
                --with-wmsclient \
                --enable-debug \
                --with-curl-config=/usr/bin/curl-config \
                --with-proj=/usr/local \
                --with-tiff \
                --with-gd=/usr/local \
                --with-jpeg \
                --with-freetype=/usr/include \
                --with-threads \
                --with-wcs \
                --with-xml2-config=/usr/bin/xml2-config \
                --with-postgis=/usr/local/pgsql/bin/pg_config \
                --with-geos=/usr/local/bin/geos-config \
                --with-sos \
                --with-agg \
                --with-agg=/usr/local

# make
# make install

# cp -p /opt/mapserver-6.0.2/mapserv /var/www/html/cgi-bin

# ./mapserv -v
MapServer version 6.0.2 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=THREADS SUPPORTS=GEOS INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE

Browser Check (Assuming httpd Installed)
---------------------------------------------------
http://localhost/cgi-bin/mapserv
No query information to decode. QUERY_STRING is set, but empty.

Tune Postgres
-------------
# vi /usr/local/pgsql/data/postgresql.conf
shared_buffers = 128MB
checkpoint_segments = 20
maintenance_work_mem = 256MB
autovacuum = off

# sysctl -w kernel.shmmax=268435456
# sysctl -p /etc/sysctl.conf

Create gis Database
-------------------
# su - postgres
$ pg_ctl stop
$ pg_ctl start

$ createuser gisuser
Shall the new role be a superuser? (y/n) y

$ createdb -E UTF8 -O gisuser gis

$ createlang plpgsql gis

$ psql -d gis -f /usr/local/pgsql/share/contrib/postgis-2.0/postgis.sql

$ psql -d gis -f /usr/local/pgsql/share/contrib/postgis-2.0/spatial_ref_sys.sql

$ echo "ALTER TABLE geometry_columns OWNER TO gisuser; ALTER TABLE spatial_ref_sys OWNER TO gisuser;" | psql -d gis

As root Install the hstore Extension in PostgreSQL
------------------------------------------
# cd /opt/postgresql-9.1.3/contrib/hstore
# make
# make install

Login to gis
------------
su - postgres
$ psql -U gisuser -d gis

Create the hstore Extension
---------------------------
gis=# create extension hstore;

As postgres Get the Following SQL Script
----------------------------------------
$ wget http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/900913.sql

Otherwise you may get the following error when trying to use osm2pgsql:
Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, 'POINT', 2 );
  failed: ERROR:  AddGeometryColumns() - invalid SRID
CONTEXT:  SQL statement "SELECT AddGeometryColumn('','', $1 , $2 , $3 , 
$4 , $5
)"
PL/pgSQL function "addgeometrycolumn" line 4 at SQL statement
 
Execute the 900913.sql File
---------------------------
$ psql -U gisuser -d gis
gis=# \i 900913.sql

Download and Build osmconvert
-----------------------------
$ wget -O - http://m.m.i24.cc/osmconvert.c | cc -x c - -lz -O3 -o osmconvert

$ cp -p osmconvert /usr/bin

As root Install osm2pgsql
------------------------
# yum install osm2pgsql

-OR-

As root Build from Source
------------------------
As root Download osm2pgsql Dependencies
---------------------------------------
yum install geos-devel proj-devel postgresql-devel libxml2-devel bzip2-devel

yum install gcc-c++ protobuf-c-devel autoconf automake libtool

As root Get the osm2pgsql Source
---------------------------------
svn co http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/

As root Compile
---------------
# cd osm2pgsql/

# ./autogen.sh

# ./configure

# make

# make install

As postgres Download OSM Data
-----------------
$ http://download.geofabrik.de/osm/north-america/us/

Download virginia.osm.pbf

$ cd /opt/osmdata

As postgres Convert PBF File
----------------
$ osmconvert virginia.osm.pbf -o=virginia.osm

Go to the Location of the OSM file
----------------------------------
$ cd /opt/osmdata

To Load the OSM File, Run the Following Command as postgres User
----------------------------------------------------------------
$ osm2pgsql virginia.osm -d gis -U gisuser -P 5432 -S default.style --hstore
osm2pgsql SVN version 0.81.0 (64bit id space)

Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
NOTICE:  table "planet_osm_point" does not exist, skipping
NOTICE:  table "planet_osm_point_tmp" does not exist, skipping
Setting up table: planet_osm_line
NOTICE:  table "planet_osm_line" does not exist, skipping
NOTICE:  table "planet_osm_line_tmp" does not exist, skipping
Setting up table: planet_osm_polygon
NOTICE:  table "planet_osm_polygon" does not exist, skipping
NOTICE:  table "planet_osm_polygon_tmp" does not exist, skipping
Setting up table: planet_osm_roads
NOTICE:  table "planet_osm_roads" does not exist, skipping
NOTICE:  table "planet_osm_roads_tmp" does not exist, skipping
Allocating memory for dense node cache
Allocating dense node cache in one big chunk
Allocating memory for sparse node cache
Sharing dense sparse
Node-cache: cache=800MB, maxblocks=102401*8192, allocation method=3
Mid: Ram, scale=100

Reading in file: virginia.osm
Processing: Node(19989k 96.1k/s) Way(878k 2.13k/s) Relation(2904 726.00/s)  parse time: 624s

Node stats: total(19989248), max(1729148313) in 208s
Way stats: total(878386), max(160964728) in 412s
Relation stats: total(2904), max(2150806) in 4s
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads

Writing way (878k)
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads

Writing relation (2903)
node cache: stored: 19989248(100.00%), storage efficiency: 72.45% (dense blocks: 18839, sparse nodes: 4149815), hit rate: 100.00%
Sorting data and creating indexes for planet_osm_polygon
Sorting data and creating indexes for planet_osm_point
Sorting data and creating indexes for planet_osm_roads
Sorting data and creating indexes for planet_osm_line
Analyzing planet_osm_point finished
Analyzing planet_osm_polygon finished
Analyzing planet_osm_roads finished
Copying planet_osm_roads to cluster by geometry finished
Analyzing planet_osm_line finished
Creating indexes on  planet_osm_roads finished
All indexes on  planet_osm_roads created  in 16s
Completed planet_osm_roads
Copying planet_osm_point to cluster by geometry finished
Copying planet_osm_polygon to cluster by geometry finished
Creating indexes on  planet_osm_polygon finished
Creating indexes on  planet_osm_point finished
All indexes on  planet_osm_point created  in 23s
Completed planet_osm_point
All indexes on  planet_osm_polygon created  in 23s
Completed planet_osm_polygon
Copying planet_osm_line to cluster by geometry finished
Creating indexes on  planet_osm_line finished
All indexes on  planet_osm_line created  in 118s
Completed planet_osm_line

Osm2pgsql took 840s overall