Saturday, May 31, 2008

Oracle: Duplicate Database using RMAN

please remove the 2 double quotes in EOF, i cant post it without the double quotes

export ORACLE_SID=TEST2
sqlplus /nolog "<<"EOF
connect / as sysdba
alter system switch logfile;
exit
EOF
rmanA.sh
export ORACLE_SID=TEST3
sqlplus /nolog "<<"EOF
connect sys/oracledba as sysdba
shutdown abort
startup nomount
exit
EOF
rm /data/oracle8/TEST3/*
rman "<<"EOF
connect target rman/rman_oracledba@test2
connect catalog rman/rman_oracledba@test1
connect auxiliary sys/oracledba@test3
run {
# set until time "to_date('2002-01-29:15:16:53','yyyy-mm-dd:hh24:mi:ss')";
# set until time "to_date('30-JAN-2002 10:50:00','dd-mon-YYYY HH24:MI:SS')";
set until time '31-JAN-2002 10:51:00';
# set until time 'sysdate-1/1000';
# set until scn = 155534;
allocate auxiliary channel d1 type disk;
allocate auxiliary channel d2 type disk;
duplicate target database to test3;
}
EOF

Wednesday, May 28, 2008

Lopez Arroyo Family Feud (century old)

The Arroyo-Lopez War
By Perry Diaz

INQUIRER.net
First Posted 14:40:00 05/23/2008

Finally, after almost 80 years of a family feud between two wealthy clans, it seems that the final battle has started. On one side of the conflict is the Arroyo clan, wealthy merchants of Chinese origin who gained political supremacy in the early 1900's when their patriarch, Jose Arroyo, was elected Senator in 1919.

With the help of his close friend -- then Senate President Manuel L. Quezon -- his younger brother, Dr. Mariano Arroyo, was appointed provincial governor in 1928.

On the other side is the Lopez clan headed by Eugenio "Eñing" Lopez who used his newspaper El Tiempo -- founded in 1901 by his father Benito Lopez, the first governor of Iloilo in 1906, who was assassinated two years later by a rival political faction -- to expose the jueteng ring that Governor Arroyo and a Chinese trader named Sualoy started in Iloilo. El Tiempo's incessant exposure of the jueteng operations finally paid off. Sualoy was charged, found guilty, imprisoned and deported to China.
That was the beginning of the Arroyo-Lopez War. As a result of the crackdown on the jueteng operations, Governor Arroyo filed a libel suit against Lopez and El Tiempo. Lopez retaliated by filing administrative charges against Governor Arroyo. Governor General Davis was also informed about the case and he sent Judge Francisco Moran to investigate. Moran discovered that Governor Arroyo was involved in the jueteng operations, including a gambling den.

Consequently, Moran dismissed the libel charges against Lopez and his newspaper. In 1930, the administrative trial found Governor Arroyo guilty of corruption and Governor General Davis relieved him from his post.

Humiliated, Jesusa Lacson Arroyo, the widow of Senator Arroyo who died in 1927, picked up the pieces and moved her entire family to Negros Occidental. One of her sons, Ignacio, would become the father of the current First Gentleman, Jose Miguel "Mike" Arroyo.

Meanwhile, Eugenio Lopez progressed in business; his brother Fernando entered politics and was elected Vice-President three times. Don Eugenio established the first airline in Asia and expanded his newspaper business. In 1962, he purchased Meralco, the country's largest electric company. His son, Eugenio "Geny" Lopez, Jr., built ABS-CBN to become the country's undisputed leader in broadcasting.

In 1972, the Lopez family suffered under the martial law regime of Ferdinand Marcos. Geny Lopez was implicated in an alleged plot to kill Marcos. Under obscure circumstances, Lopez escaped from detention and slipped out of the country. Marcos' brother-in-law, Kokoy Romualdez, then took over Meralco. When Marcos was ousted in 1986, Cory Aquino returned Meralco and ABS-CBN to the Lopezes.

For more than 20 years, the Lopezes had undisputed control of Meralco. They also diversified into new business ventures. Over the past several years, ABS-CBN became a pain in the neck of President Gloria Macapagal- Arroyo. Their coverage of the various scandals involving the First Couple have contributed much to the Arroyos' negative public image.

It is no wonder then that Meralco is now in the crosshairs of President Arroyo's sight. The joint congressional hearing chaired by Senator Miriam Defensor-Santiago and Congressman Juan Miguel "Mikey" Arroyo has stirred to life a family feud dormant for 78 years. There are speculations that the real reason for the Meralco "witch hunt" is for government to take over Meralco and break it up into smaller companies. If this should happen, guess who would take over a divested Meralco?
Let's look at one who has been at the forefront of the battle: Winston Garcia, President and General Manager of the Government Service Insurance System (GSIS). His aggressive and arrogant demeanor in the Meralco boardroom -- he is a recent member on the Meralco board, representing GSIS which has 23% ownership of Meralco -- has made a lot of people wonder what his ulterior motive might be. Many believe that Garcia is on the board to wage a "proxy war" for the Arroyos.

For one thing, Garcia is not the typical government bureaucrat. He is a scion of a powerful political dynasty in Cebu with close ties to Malacañang. His father, Pablo, is a congressman and concurrently Deputy Speaker of the House. His brother, Pablo John, is also a congressman. And his sister, Gwendolyn, is the current Governor of Cebu. She announced recently that she is a candidate for Vice President in 2010.

In addition, the Garcia family has large stockholdings in the Aboitiz-owned Visayan Electric Company (VECO), the country's second largest private electric utility. The corporate officers include three Garcias, to wit: Dennis A. Garcia, President and General Manager; Ramontito A. Garcia,Treasurer; and Jess Anthony N. Garcia, legal counsel and Assistant Corporate Secretary. Of the 11 members of the VECO Board of Directors, five are Garcias, namely, Dennis N.A. Garcia, Ramontito E. Garcia, Gil A. Garcia II, Charles Sylvester A. Garcia, and Antonio V. A. Garcia de Escaño.
The Aboitizes have five members of the Board. Recently a news account reported that Winston Garcia is serving VECO as a lawyer on retainer. The question is: What would VECO -- and Winston Garcia -- stand to gain if Meralco were broken up into smaller companies?

It is also common knowledge that the Aboitizes are business cronies of the First Couple. With the Lopezes trying hard to defend themselves from a pack of wolves, it would probably take a miracle to survive these attacks. But miracles do happen, and they happen when least expected. The last question is: What would the Arroyos stand to gain if and when Meralco breaks up?



Ruby on Rails on Oracle: A Simple Tutorial

Source: Oracle.com

Ruby on Rails on Oracle: A Simple Tutorial

by Richard Monson-Haefel

Rails is an easy framework to work with, but like any technology it takes time to master.

Published April 2006

Comments about this article? Visit the Ruby/RoR Discussion Forum

You may have already heard about Ruby on Rails, the new application framework that seems to be taking the Web development community, in particular J2EE and PHP programmers, by storm.

Rails is a capable Web application platform and has, in less than two years, gained significant traction among J2EE and PHP programmers. The attraction of both J2EE and PHP programmers makes a lot of sense when you look at the strengths of Rails. For one thing, it uses a strict model-view-controller architecture that any self-respecting design-patterns wonk would admire—this explains its attraction to J2EE developers. Second, it’s easy to build basic systems with Rails—which is attractive to PHP developers.

However, Rails has some pretty significant limitations from a database perspective. Rails makes a lot of assumptions about your database layout and application needs. For example, Rails assumes that all tables use a single, non-compound, primary key. Compound primary keys are not supported! In addition, Rails does not support two-phase commit; it supports multiple databases, but cannot coordinate transactions among them.

This article is not intended to be a booster piece for Rails nor is it an expose. It’s simply an introduction to the technology. It contains both praise and criticism. At times the criticism might appear a bit heavy handed (especially to Rails enthusiasts), but don’t be fooled. Using any Web application framework is going to be tricky, whether it’s J2EE, ASP.NET, or PHP. In the long run, you can be a lot more productive with Rails than you can be with many other Web application development platforms, but it takes time to learn the ropes.

What is Ruby? What is Rails?

Ruby is a dynamic programming language similar in many respects to Perl, Python, and Smalltalk, but it is its own animal. Java and PHP programmers seem to pick up the language pretty easily and they have been Ruby’s biggest supporters. But others have been attracted to the language, too; including Don Box, who is well known as one of the wonkiest-wonks of the Microsoft world.

Ruby is not new; it was created in 1993, making it older than Java or PHP, both of which were first introduced to the public in 1995. So while Ruby is a mature language, it’s been less popular than some other languages. As a result, the ecosystem that surrounds the Ruby programming language is not as rich as those that have grown up around Java, PHP, or Perl. Consequently, you will find fewer frameworks, libraries, books, Web sites, blogs, and other resources dedicated to the language.

The marketing impotence of the Ruby community changed recently, when David Heinemeier Hanson introduced the Rails framework, arguably the most popular application of Ruby in its history. Rails extends the Ruby programming language into a domain specific language especially well suited for web development. It also leverages ActiveRecord, another language extension that adapts Ruby to object-relational persistence. Other than Rails’ lack of support for compound primary keys and two-phase commit, its biggest obstacle to adoption has been that you need to learn a new programming language to use it. This is not something that most people can simply ignore with a lot of hand-waving; learning a new language can be a fun but daunting task.

If, however, you were interested in expanding your resume, I can think of no other language I would recommend higher than Ruby. Ruby represents the culmination of 10 years of development without the tampering of commercial interests. As a result, Ruby is a delight to work with and, in many cases, is an order of magnitude more productive than Java, C, or Microsoft .NET languages. (The exception may be IronPython, a port of the Python language to the Microsoft .NET environment. Python, like Ruby, is a dynamic and productive programming language.)

What is Rails For?

Rails is designed from the ground up to create dynamic Web sites that use a relational database backend. It adds key words to the Ruby programming language that make Web applications easier to configure. In addition, it’s designed to automatically generate a complete, if somewhat crude, Web application from an existing database schema. The latter is both Ruby’s greatest strength and its Achilles’ heel. Rails makes assumptions about database schema naming conventions that, if followed, make generating a basic Web site a matter of executing single command. But to do this may require additional configurations or in some cases may not be possible at all. You’re also likely to find that just about every database convention that Rails expects can be overridden, but the more overriding that is needed, the less productive the platform becomes. This is why Rails is great when developing “green-field” applications with new databases. Unfortunately, it’s not a great solution when dealing with legacy systems.

The best way to appreciate Rails in green-field application development is via an example. If you already have an Oracle database installed on which you can create new databases and tables, it should take less than 15 minutes to create a complete Web application. In this case, we’ll use Ruby of Rails to build a product catalog.

Example: A Simple Product Catalog

Last year I started investing in high-grade (HG) comic books, specifically old issues from as far back as 1946. I created a simple Ruby on Rails database application that allows me to insert, remove, modify and delete new comics as I buy and sell them. It’s only intended for my use, so I kept it pretty simple. The application that will be developed in this article is a trimmed down version of the Ruby on Rails application I use at home.

Although Rails and Oracle Database can be used on a variety of platforms, this article focuses on Windows XP, arguably one of the most frequently used operating systems by Oracle application developers. This example is pretty simple; it’s essentially the database equivalent of a “Hello World” programming language example. It’s designed to give you a small taste of Ruby, but it doesn’t represent the full capabilities of Rails, any more than a “Hello World” example demonstrates the full capabilities of any programming language.

If you experience problems running this example, it’s likely to be for one of three reasons: Either you downloaded the wrong code, your database is not set up to allow you to connect to it, or your Windows XP operating system is giving you problems. In developing this example, I had a number of problems related to versioning and database configuration—all of which were a result of ignorance. I leaned heavily on a friend of mine, Michael Carland, to get everything working and to make this example as simple as possible.

The fact of the matter is, getting Ruby on Rails and Oracle to work together is not trivial. In fact, it can be a bit frustrating at times. Follow the directions in this article exactly and you shouldn’t have problems. However, once you step outside the boundaries of this example, expect to have some issues. Rails can be very productive, but it’s a command-line development environment and doesn’t come with all of the “automagic” typically associated with advanced integrated development environments. If you are not a “do-it-yourself” technical person, than I wouldn’t recommend Rails to you at this time.

Step 1: Set up the Oracle database

You wouldn’t be reading this article if you were not interested in using Rails in combination with Oracle, so you’ll need to have an installed instance of the Oracle database and you’ll need to add a single table to the database. It’s important that you follow the exact naming conventions used in this article, otherwise a lot of the automatic code generation provided by Rails simply won’t work (without some tweaking). The table you need to create is described as follows:

CREATE TABLE comics ( id NUMBER(10) NOT NULL, title VARCHAR2(60), issue NUMBER(4), publisher VARCHAR2(60), PRIMARY KEY (id) ); CREATE SEQUENCE comics_seq;

There is a SQL Script file here which you can use to create the table and add some product data. I suggest that you use it so that your application is consistent with the one being developed here. The easiest way to do that is to use SQL*Plus as follows. (The assumption is that you already have an Oracle database installed and know how to use it.)

Using SQL*Plus, create a user with DBA privileges that you can use for this application.

SQL> GRANT dba TO ruby IDENTIFIED BY ruby; SQL> ALTER USER ruby DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp; SQL> EXIT

Using the SQL file, create the application table, COMICS, and insert some example data.

C:\> sqlplus ruby/ruby@rails @comics.sql

As you may have noticed, the COMICS table created for this example is plural, which may appear problematic since a common approach is to give tables singular names (e.g. COMIC). However, Rails takes the approach that tables should be named in the plural. This default can be overridden using a Rails configuration but using plural names is easier.

Step 2: Install Ruby, RubyGems, Rails, and the Rails Oracle library

There are two pieces of software you’ll need in order to use Rails on Windows XP: the Ruby programming language with RubyGems installation package, Rails 1.0 (1.1 was recently released; this articles addresses 1.0 only), and the Rails Oracle database library. To download and install Ruby with the Gems package installer, do the following.

  1. Go to http://rubyinstaller.rubyforge.org/.
  2. Download the “One-Click Ruby Installer”.
  3. Follow the installation instructions.

Once the Ruby programming platform is installed you can use RubyGems, a Ruby application that allows you to install Ruby frameworks very easily. To install the Rails application development framework, all you need to do is open a command-line prompt and type in a single command.

C:\> gem install rails -v 1.0.0 --remote

Now that you have Ruby, RubyGems, and Rails installed you can install a specialized code library that will allow your Rails applications to talk to your Oracle database server. To download and install Oracle Rails library, go to http://rubyforge.org/projects/ruby-oci8, download ruby-oci8-0.1.13-mswin.r to your C drive, and then using your command window, execute the following command.

C:\> ruby ruby-oci8-0.1.13-mswin.rb

Assuming that everything went smoothly, you have now installed Ruby, Rails, and the Rails-Oracle connection library. You are now ready to create your first Ruby on Rails Web application.

Step 3: Create the Web Application

In order to create your new Rails application, you will need to create a new Rails project as follows.

Create a new project using the rails command line application (this will automatically create a new directory).

C:\> rails comics_catalog

Change directories so you are in the new project directory created in the previous step.

C:\> cd comics_catalog C:\comics_catalog>

Now that you have a new Rails project directory, you’ll need to configure your project so that the Rails applications will use the Rails-Oracle connection library.

Within your project directory, there is a directory called config and in it is a file named database.yml. You need to edit database.yml using your favorite text editor. Initially, the file will look like this:

development:
adapter: mysql
database: rails_development
host: localhost
username: root
password:

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: rails_test
host: localhost
username: root
password:

production:
adapter: mysql
database: rails_production
host: localhost
username: root
password:

Different databases require different connection properties. Rails is set up to work with MySQL by default, but you want to re-configure this project to use Oracle. Change the development properties as described on this Oracle on Rails wiki page. (You could change the test and production properties also, but the scope of this article doesn’t include testing or production releases.)

There are a number of approaches to creating a Web application in Rails, but the simplest by far is to use scaffold, a command line feature in Rails 1.0.0, which will build the entire application in a single command.

C:\comics_catalog> ruby script/generate scaffold Comic

Other than a cascade of output in the command window, what just happened? Well, the Rails code generator created model, view, and controller Ruby code to access the COMICS table. In this case you created the application using the Rails scaffold, which does all the work for you. If you make any changes to the database tables, you’ll need to run the scaffold command again. Otherwise, your application may not work.

Now that the web application has been generated, you can start the Ruby Web server, WEBRick.

C:\comics_catalog> ruby script/server

You can change the Ruby code for your application or the COMICS table at anytime without having to restart the web server. However, if you change the database configuration file (i.e. database.yml) you will need to restart the server.

Now you can access your Rails Comic Catalog application on your own development machine, using your favorite Web browser. Just access the following URL.

http://localhost:3000/comics/list

Your browser should show a list of comics in your Catalog like the one in Figure 1.


Figure 1: Product Catalog List

When you use the scaffold to create a Rails Web application, it will automatically create three Web components that allow you to see a list of all records in the target database table and to insert, modify, and delete records in that table. Figure 1 shows a list of all of the sample data that was inserted into your database table when you executed the SQL script at the start of this tutorial.

In addition to the Listing view, there is also a details view. Just click on any of the “Show” links to see a Web paged dedicated to displaying the data in that particular record. Figure 2 is an example of this details page.


Figure 2: The Details Page

You can also edit any record in the database table. Click on the “Back” link, or use your browser back button to get back to the Listing page, then click on the “Edit” link of any record. Figure 3 shows an example of the Editing view of one of the records in the COMICS database table.


Figure 3: The Editing View

You can also add new records to the COMICS table by going back to the Listing view and clicking on the “New Comic” link. This will present you with an insertion view similar to the one in figure 3, except the fields will all be blank.

Mastering Rails

While the Product Catalog example showed how easy it is to create a very simple application using Rails, it’s not all that useful except for tracking inventory. You can create much more complicated Web applications with Rails, but that will require that you jump into the code a bit, which would require some study. Rails is an easy framework to work with, but like any technology it takes time to master. At this point, I can only recommend Rails to technically-savvy individuals and development teams who are embarking on “green-field” application development. If you don’t fall into this rough category, I wouldn’t recommend using Rails until the tooling has matured.

In order to really master Rails, you should read a book, a number of which will be available later this year, but one that is very good and is available now is Agile Web Programming with Ruby on Rails by David Heninmier Hanson and Dave Thomas (Published by Pragmatic Bookshelf, 2005). Hanson is, of course, the guy who created Rails and Thomas is one of the authors of Programming Ruby: The Pragmatic Programmers' Guide (Pragmatic Bookshelf; 2nd edition, 2004).


Oracle: Query DB Cache Advice

select
size_for_estimate c1,
buffers_for_estimate c2,
estd_physical_read_factor c3,
estd_physical_reads c4
from
v$db_cache_advice
where
name = 'DEFAULT'
and
block_size = (SELECT value FROM V$PARAMETER
WHERE name = 'db_block_size')
and
advice_status = 'ON'

Oracle: Query Used space in Meg by segment type

rem -----------------------------------------------------------------------
rem Filename: usedsp.sql
rem Purpose: Used space in Meg by segment type
rem Author: Frank Naude, Oracle FAQ
rem -----------------------------------------------------------------------

set pagesize 50000
set line 80

col "Total Used Meg" format 999,999,990
col "Data part" format 999,999,990
col "Index part" format 999,999,990
col "LOB part" format 999,999,990
col "RBS part" format 999,999,990

tti 'Used space in Meg by segment type'

select sum(bytes)/1024/1024 "Total Used",
sum( decode( substr(segment_type,1,5), 'TABLE', bytes/1024/1024, 0))
"Data part",
sum( decode( substr(segment_type,1,5), 'INDEX', bytes/1024/1024, 0))
"Index part",
sum( decode( substr(segment_type,1,3), 'LOB', bytes/1024/1024, 0))
"LOB part",
sum( decode(segment_type, 'ROLLBACK', bytes/1024/1024, 0))
"RBS part",
sum( decode(segment_type, 'TEMPORARY', bytes/1024/1024, 0))
"TEMP part"
from sys.dba_segments
/
tti off

tti "Total database size"

select sum(bytes)/1024/1024 "Total DB size in Meg"
from sys.v_$datafile
/
tti off

Tuesday, May 27, 2008

Exporting your Printer Configuration in Linux

Have you ever encounter when you need to transfer hundreds of printer configuration from one linux box to another, well I have fortunately I have found an article on the web on how to easily you can export those configurations.

Saving the Configuration File

When you save your printer configuration using Printer Configuration Tool, it creates its own configuration file that is used to create the /etc/printcap file that the printer daemon (lpd) reads. You can use the command line options to save or restore this file. If you save your /etc/printcap file and overwrite your existing /etc/printcap file with the saved file, your printer configuration will not be restored. Each time the printer daemon is restarted, it creates a new /etc/printcap file from the special Printer Configuration Tool configuration file. If you have configured a backup system for your configuration files, you should use the following method to save your printer configuration. If you added any custom settings in the /etc/printcap.local file, you should save it as part of your backup system also.

To save your printer configuration, type this command as root:

/usr/sbin/redhat-config-printer-tui --Xexport > settings.xml

Your configuration is saved to the file settings.xml.

If you save this file, you can restore your printer settings. This is useful if your printer configuration is deleted, you reinstall Red Hat Linux and do not have your printer configuration file anymore, or you want to use the same printer configuration on multiple systems. To restore the configuration, type this command as root:

/usr/sbin/redhat-config-printer-tui --Ximport <>

If you already have a configuration file (you have configured one or more printers on the system already) and you try to import another configuration file, the existing configuration file will be overwritten. If you want to keep your existing configuration and add the configuration in the saved file, you can merge the files with the following command (as root):

/usr/sbin/redhat-config-printer-tui --Ximport --merge <>

Your printer list will then consist of the printers you configured on the system as well as the printers you imported from the saved configuration file. If the imported configuration file has a print queue with the same name as an existing print queue on the system, the print queue from the imported file will override the existing printer.

After importing the configuration file (with or without the merge command), you must restart the printer daemon with the command /sbin/service lpd restart or by starting Printer Configuration Tool and clicking Apply.

Setup Oracle Standby Database ( Data Guard )

Oracle9i Data Guard is the new name for Oracle8i Standby Server, incorporating a large number of new features. In this article I shall only focus on those relevant to the "Oracle9i Database: New Features For Administrators" OCP exam. For more detailed information read the Oracle9i Data Guard Concepts and Administration documentation.

Architecture

The Oracle9i Data Guard architecture incorporates the following items:

  • Primary Database - A production database that is used to create standby databases. The archive logs from the primary database are transfered and applied to standby databases. Each standby can only be associated with a single primary database, but a single primary database can be associated with multiple standby databases.
  • Standby Database - A replica of the primary database.
  • Log Transport Services - Control the automatic transfer of archive redo log files from the primary database to one or more standby destinations.
  • Network Configuration - The primary database is connected to one or more standby databases using Oracle Net.
  • Log Apply Services - Apply the archived redo logs to the standby database. The Managed Recovery Process (MRP) actually does the work of maintaining and applying the archived redo logs.
  • Role Management Services - Control the changing of database roles from primary to standby. The services include switchover, switchback and failover.
  • Data Guard Broker - Controls the creation and monitoring of Data Guard. It comes with a GUI and command line interface.

The services required on the primary database are:

  • Log Writer Process (LGWR) - Collects redo information and updates the online redo logs. It can also create local archived redo logs and transmit online redo to standby databases.
  • Archiver Process (ARCn) - One or more archiver processes make copies of online redo logs either locally or remotely for standby databases.
  • Fetch Archive Log (FAL) Server - Services requests for archive redo logs from FAL clients running on multiple standby databases. Multiple FAL servers can be run on a primary database, one for each FAL request. .

The services required on the standby database are:

  • Fetch Archive Log (FAL) Client - Pulls archived redo log files from the primary site. Initiates transfer of archived redo logs when it detects a gap sequence.
  • Remote File Server (RFS) - Receives archived and/or standby redo logs from the primary database.
  • Archiver (ARCn) Processes - Archives the standby redo logs applied by the managed recovery process (MRP).
  • Managed Recovery Process (MRP) - Applies archive redo log information to the standby database.

Database Synchronization Options

Data Guard can be configured to run with varying synchronization modes indicating the potential for data loss:

  • No-Data-Loss mode : This simply means that the log transport services will not acknowledge modifications to the primary database until they are available to the standby database. This doesn't mean that the modifications have been applied to the standby database, merely that the log information is available to the log apply services should failover occur. This mode is implemented using standby redo logs on the standby server.
  • No-Data-Divergence mode : This is an extension of the no-data-loss mode whereby modifications to the primary database are prevented if conectivity between the primary and at least one standby database is unavailable.
  • Minimal-Data-Loss mode : When the performance requirements of the primary database are the top priority this mode provides the optimum balance of data protection and performance.

Setup No-Data-Divergence

To setup no-data-divergence, the most extreme level of data protection, then do the following:

Setup Primary Database

  • Shutdown the database using: SHUTDOWN IMMEDIATE
  • Backup all database files.
  • Add an entry for the standby server into the tnsnames.ora file:
stby1=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = myServerName)(PORT = 1512))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = stby1.world)
    )
  )
  • Assuming your database in already in ARCHIVELOG mode one of the archive destinations will be set. Add the other entires:
CONTROL_FILES=primary.ctl
COMPATIBLE=9.0.1.0.0
LOG_ARCHIVE_START=true
LOG_ARCHIVE_DEST_1='LOCATION=C:\Oracle\Oradata\TSH1\Archive MANDATORY REOPEN=30'
LOG_ARCHIVE_DEST_2='SERVICE=stby1 LGWR SYNC AFFIRM'
LOG_ARCHIVE_DEST_STATE_1=enable
LOG_ARCHIVE_DEST_STATE_2=enable
LOG_ARCHIVE_FORMAT=arc%t_%s.arc
REMOTE_ARCHIVE_ENABLE=true

The LGWR SYNC AFFIRM keywords indicate that the Logwriter should synchronously write updates to the online redo logs to this location and wait for confirmation of the write before proceeding. The remote site will process and archive these standby redo logs to keep the databases synchronized. This whole process can impact performance greatly but provides maximum data security.

  • Startup the database using: STARTUP PFILE=C:\Oracle\Admin\TSH1\pfile\init.ora
  • Create standby database controlfile using: ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'c:\stbycf.f';

Setup Standby Database

  • Copy the production backup files to the standby server.
  • Copy the standby controlfile to the standby server.
  • Alter the control_files and archive parameters of the init.ora as follows:
SERVICE_NAMES = stby1
CONTROL_FILES=standby.ctl
COMPATIBLE=9.0.1.0.0
LOG_ARCHIVE_START=true
LOCK_NAME_SPACE=stby1
FAL_SERVER=prim1
FAL_CLIENT=stby1
 
# Uncomment is filename conversion is needed
#DB_FILE_NAME_CONVERT=("/primary","/standby")
#LOG_FILE_NAME_CONVERT=("/primary","/standby")
 
STANDBY_ARCHIVE_DEST=C:\Oracle\Oradata\TSH1\Archive
LOG_ARCHIVE_DEST_1='LOCATION=C:\Oracle\Oradata\TSH1\Archive'
LOG_ARCHIVE_TRACE=127
LOG_ARCHIVE_FORMAT=arc%t_%s.arc
STANDBY_FILE_MANAGEMENT=auto
REMOTE_ARCHIVE_ENABLE=true
  • Add the following entries into the listener.ora file:
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = myHost)(PORT = 1512))
)
 
STANDBY_LISTENER = (ADDRESS_LIST=
 (ADDRESS=(PROTOCOL=tcp)(PORT=1512)(HOST=myHost))
)

The file should resemble the following:

# LISTENER.ORA Network Configuration File: C:\Oracle\Ora901\network\admin\listener.ora
# Generated by Oracle configuration tools.
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
      )
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = myHost)(PORT = 1521))
      )
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = myHost)(PORT = 1512))
      )
    )
    (DESCRIPTION =
      (PROTOCOL_STACK =
        (PRESENTATION = GIOP)
        (SESSION = RAW)
      )
      (ADDRESS = (PROTOCOL = TCP)(HOST = myHost)(PORT = 2481))
    )
  )
 
STANDBY_LISTENER = (ADDRESS_LIST=
 (ADDRESS=(PROTOCOL=tcp)(PORT=1512)(HOST=myHost))
)
 
 
 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC = (SID_NAME = PLSExtProc)(ORACLE_HOME = C:\Oracle\Ora901)(PROGRAM = extproc))
    (SID_DESC = (ORACLE_HOME = C:\Oracle\Ora901) (SID_NAME = TSH1)
    )
  )
  • Reload the listener file using lsnrctl reload from the command prompt.
  • Add the following entry into the tnsnames.ora file:
stby1=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = myServerName)(PORT = 1512))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = stby1.world)
    )
  )

Create standby redo logs on the standby database to receive online redo information from the Logwriter on the primary database. The minimum number of groups required is an exact match, number and size, of the primary database, but performance may be increased by adding more:

ALTER DATABASE ADD STANDBY LOGFILE GROUP 10
  ('C:\Oracle\Oradata\TSH1\redo1a.log','C:\Oracle\Oradata\TSH1\redo1b.log') SIZE 500K;

Start Managed Standby Recovery

During managed recovery the transfer of archivelogs is controlled by the servers without user intervention.

  • Copy all archive logs from the primary to the standby server. This is the only time you should need to do this.
  • From sqlplus do the following:
SQL> CONNECT sys/password AS SYSDBA
SQL> STARTUP NOMOUNT PFILE=C:\Oracle\Admin\TSH1\pfile\init.ora
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Protect Primary Database

Now that Data Guard is configured and running the primary database can be prevented from applying updates unless the update has been sent to at least one standby location. Connect to the primary database and execute:

ALTER DATABASE SET STANDBY DATABASE PROTECTED;

Cancel Managed Standby Recovery

To stop managed standby recovery:

SQL> -- Cancel protected mode on primary
SQL> CONNECT sys/password@primary1 AS SYSDBA
SQL> ALTER DATABASE SET STANDBY DATABASE UNPROTECTED;
SQL> 
SQL> -- Cancel recovery if necessary
SQL> CONNECT sys/password@standby1 AS SYSDBA
SQL> RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> ALTER DATABASE OPEN READ ONLY;

The database can subsequently be switched back to recovery mode as follows:

SQL> -- Startup managed recovery
SQL> CONNECT sys/password@standby1 AS SYSDBA
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP NOMOUNT PFILE=C:\Oracle\Admin\TSH1\pfile\init.ora
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
 
SQL> -- Protect primary database
SQL> CONNECT sys/password@primary1 AS SYSDBA
SQL> ALTER DATABASE SET STANDBY DATABASE PROTECTED;

Activating A Standby Database

If the primary database is not available the standby database can be activated as a primary database using the following statements:

SQL> -- Cancel recovery if necessary
SQL> RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> ALTER DATABASE ACTIVATE STANDBY DATABASE;

Since the standby database is now the primary database it should be backed up immediately. The previous primary database can then be configured as a standby.

Backup Standby Database

Backups of the standby database can only be performed if the database is shut down or in read only mode. Read only mode is best for managed recovery systems as archive logs will still be transfered during the backup process, thus preventing gap sequences. Once the server is in the desired mode simply copy the appropriate database files.

Database Switchover

A database can be in one of two mutually exclusive modes (primary or standby). These roles can be altered at runtime without loss of data or resetting of redo logs. This process is known as a Switchover and can be performed using the following statements:

-- Convert primary database to standby
CONNECT sys/change_on_install@prim1 AS SYSDBA
ALTER DATABASE COMMIT TO SWITCHOVER TO STANDBY;
 
-- Shutdown primary database
SHUTDOWN IMMEDIATE;
 
-- Mount old primary database as standby database
STARTUP NOMOUNT PFILE=C:\Oracle\Admin\TSH1\pfile\init.ora
ALTER DATABASE MOUNT STANDBY DATABASE;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
 
 
-- Convert standby database to primary
CONNECT sys/change_on_install@stby1 AS SYSDBA
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
 
-- Shutdown standby database
SHUTDOWN IMMEDIATE;
 
-- Open old standby database as primary
STARTUP PFILE=C:\Oracle\Admin\TSH1\pfile\init.ora

This process has no affect on alternative standby locations. The process of converting the instances back to their original roles is known as a Switchback. The switchback is accomplished by performing another switchover.

Database Failover

Graceful Database Failover occurs when database failover causes a standby database to be converted to a primary database:

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
ALTER DATABASE ACTIVATE STANDBY DATABASE;

This process will recovery all or some of the application data using the standby redo logs, therefore avoiding reinstantiation of other standby databases. If completed successfully, only the primary database will need to be reinstatiated as a standby database.

Forced Database Failover changes one standby database to a primary database. Application data may be lost neccessitating the reinstantiation of the primary and all standby databases.

Automatic Archive Gap Detection

Gaps in the sequence of archive logs can be created when changes are applied to the primary database while the standby database is unavailable. In Oracle8i the archive redo logs associated with these gaps had to be identified using the V$ARCHIVE_GAP view and copied manually to the standby server before managed recovery could be initiated again. In Oracle9i most of these gap sequences can be resolved automatically. The following parameters must be added to the standby init.ora file where the values indicate net services names.

FAL_SERVER = 'primary_db1'
FAL_CLIENT = 'standby_db1'

The FAL server is normally the primary database, but can be another standby database. Once the standby database is placed in managed recovery mode it will automatically check for gap sequences. If it finds any it will request the appropriate files from the primary database via the FAL server. If the gap sequences cannot be resolved the files have to be recovered manually.

Background Managed Recovery

In Oracle8i managed recovery caused the user session to hang until the process was stopped by the user. This type of recovery is still available along with a background recovery that spawns a new background process and frees the user session:

-- User session hangs
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
 
-- User session released
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Delayed Redo Application

Application of the archived redo logs to the standby database can be delayed using the DELAY keyword. If a rogue statement significantly damages the primary database the DBA can choose to switch to the standby database, which will be in a state prior to this action:

-- Delay application of archived redo logs by 30 minutes.
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DELAY 30;
 
-- Return to no delay (Default).
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE NODELAY;

For further information see:

CUPS printer commands

More information can be found on the CUPS website: http://www.cups.org/documentation.php

Basic CUPS commands

cancel

Allows you to cancel all jobs, all jobs on a specific printer or individual jobs

lpq

show printer queue status on specific printer, or all printers

lpq -P printername

lists all queued jobs on target printer

accept

accept jobs sent to a destination

reject

reject jobs sent to a destination

lp

show printer queue status on specific printer, or all printers

lpq -P printername

lists all queued jobs on target printer

lp

submits files for printing or alters a pending job

lpadmin

configure cups printers and classes

lpadmin -x printername

deletes target printer

lpinfo

lists the available devices or drivers known to the CUPS server

lpmove

moves the specified job or all jobs from source to destination

lpoptions

display or set printer options and defaults

lprm

cancels print jobs that have been queued for printing

lpstat

displays status information about the current classes, jobs, and printers

lpstat -t

Lists all printers and all status information

lpstat -a

Lists all printers and accepting state

Printer hangs up on a job

  1. Turn off the printer
  2. Ssh into the print server
  3. lpq -P PrinterName

This will list all jobs queued on the hung printer. In most cases, deleting all submitted jobs is safest

  1. Cancel -a PrinterName

Cancels all submitted jobs on target printer

  1. Restart printer

Check that jobs are printing

Clearing Boelter Lab print queues daily

  1. cancel -a `lpstat -t | grep disabled | awk '{print $2}'`

This will list all printers that are currently disabled, and cancel queued jobs on those printers

  1. /usr/bin/enable `lpstat -t | grep disabled | awk '{print $2}'`

This will re-enable the stopped print queues

  1. lpstat -t | grep disabled | awk '{print $2}'

This checks to see that all printers are re-enabled. Should return nothing.

Remove printers from client computer

  1. lpadmin -x `lpstat -a | awk '{printf $1 " "}'`

Lists all printers on client, sorts the printer names into a string, then issues lpadmin -x (removal) command to each printer. Command only deletes a printer at a time right now.