Monday 27 December 2010

وَلَهُمْ عَذَابٌ أَلِيمٌ

وَلَهُمْ عَذَابٌ أَلِيمٌ

Sunday 26 December 2010

Make XP auto login

Click Start > Run and type

CONTROL USERPASSWORDS2

Select the user account from the list (the account to which you want to automatically logon). Uncheck Users must enter a user name and password to use this computer option, and click Ok. Type the user account password and complete the process.

For Windows XP Home, don't try to auto-login as the built-in Administrator, as you'll receive an error message.

Thanks to site: http://windowsxp.mvps.org/Autologon.htm

Friday 17 December 2010

Tracing ORA-01427

To Trace Oracle error ORA-01427


SQL> alter system set events '1427 trace name ERRORSTACK level 10';


After the error occurs, see the trace generated in the udump directory.

To disable tracing:

SQL> alter system set events '1427 trace name ERRORSTACK off';


Testing on 15 Dec 2010, now sql that caused the error, is listed on trace file.

Stats Pack or AWR

Since none of my databases are Enterprice Licenced, I dont get to use AWR year on year.
So hence alwasy foget the AWR command, still surviving with the stats pack command.

Here's one that I need remember:


@?/rdbms/admin/awrrpt.sql

Thursday 16 December 2010

Munin 10+ cpu patch

for 10 or cpu box:


please login to lnx-db28.nid as root.

vi /usr/share/munin/plugins/cpu

search for NCPU

remove a space e.g.

From

NCPU=`expr \`grep '^cpu. ' /proc/stat | wc -l\` - 1`


To (Only removing the space after cpu.)

NCPU=`expr \`grep '^cpu.' /proc/stat | wc -l\` - 1`


Restart munin node on that box

/etc/init.d/munin-node restart

How to find the tables that have stale statistics?

How to find the tables that have stale statistics?

SET SERVEROUTPUT ON

DECLARE
ObjList dbms_stats.ObjectTab;
BEGIN

dbms_stats.gather_database_stats(objlist=>ObjList, options=>'LIST STALE');

FOR i in ObjList.FIRST..ObjList.LAST
LOOP
dbms_output.put_line(ObjList(i).ownname || '.' || ObjList(i).ObjName || ' ' || ObjList(i).ObjType || ' ' || ObjList(i).partname);
END LOOP;
END;
/


ref: http://oraclespin.wordpress.com/2009/04/19/how-to-find-the-tables-that-have-stale-statistics/



DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>'AR_SILVER1_AUTOSLIM', objlist=>ObjList, options=>'LIST STALE');

Saturday 16 October 2010

OpenBravo

Found below link very useful:

http://forge.openbravo.com/plugins/espforum/view.php?group_id=101&forumid=434922&topicid=7015387

Keeing a copy here, in case the orginal is moved or broken.


==============
Discount Fixed
==============

Step 1: Create a new button for the main screen.

Login as Admin and goto maintainence --> resources and add the following line to "Ticket.Buttons"

< button key="button.discount" name="button.discount" code="Code.Discount" />


Step 2: Create a new resource called "Code.Discount" and add the follwing code to it.

import com.openbravo.format.Formats;
import com.openbravo.pos.ticket.TicketLineInfo;
import com.openbravo.pos.ticket.TicketProductInfo;

discountamount = sales.getInputValue();

index = sales.getSelectedIndex();
if (index >= 0) {
line = ticket.getLine(index);
if (line.getPrice() > 0.0 && discountamount > 0.0) {

sdiscount = Formats.CURRENCY.formatValue(discountamount);

ticket.insertLine(index + 1,
new TicketLineInfo(
"Discount " + sdiscount,
line.getProductTaxCategoryID(),
line.getMultiply(),
-discountamount,
line.getTaxInfo()));
sales.setSelectedIndex(index + 1);
} else {
java.awt.Toolkit.getDefaultToolkit().beep();
}
} else {
java.awt.Toolkit.getDefaultToolkit().beep();
}


Step 3: Add permission to who all can use this function.

Either Administrator, Manager or Employees etc...

The following line will be added to maintainence ==> roles.


< class name="button.discount" />


Restart your POS and goto sales screen to check out your new button........ Viola


I would add one more step:

add following line in the pos_messages.properties located in Locales folder so a proper label on the button is placed.


button.discount=Discount



==================
Discount Percentag
==================

Here is the code for a user entered discount percentage rate.

Pros: You can enter discount amount. i.e. 10% of total ticket entered as 10

20% of total ticket entered as 20 and so on

Cons: You can not remove the discount once entered. ( can anyone point me how to add this exception as it gives out a strange error )



Input this code in a new resource called "discount.Total"



// % Discount for the total of the receipt

import com.openbravo.format.Formats;
import com.openbravo.pos.ticket.TicketLineInfo;
import com.openbravo.pos.ticket.TicketProductInfo;
import java.util.Properties;

discountperc = JOptionPane.showInputDialog(null, "Input percentage.....");
double discountrate = Double.parseDouble(discountperc);
discountrate = discountrate/100.00;

total = ticket.getTotal();
if (total > 0.0) {
sdiscount = Formats.PERCENT.formatValue(discountrate);

taxes = ticket.getTaxLines();
for (int i = 0; i < taxes.length; i++) {
taxline = taxes[i];
ticket.insertLine(ticket.getLinesCount(),
new TicketLineInfo(
"Discount " + sdiscount + " of " + taxline.printSubTotal(),
taxline.getTaxInfo().getTaxCategoryID(),
1.0,
-taxline.getSubTotal() * discountrate,
taxline.getTaxInfo()));
}
sales.setSelectedIndex(ticket.getLinesCount() - 1);
} else {
java.awt.Toolkit.getDefaultToolkit().beep();
}


now create a new button in "Ticket.Buttons"


< button key="button.discount" name="button.discount" code="discount.Total" />


and also add the permission in maintenance -> roles


< class name="button.discount" />

Wednesday 6 October 2010

Temp tablespace


CREATE TEMPORARY TABLESPACE temp_n TEMPFILE '/u01/oracle/oradata/NIDEV/temp_01.dbf' SIZE 500M
autoextend off extent management local UNIFORM SIZE 1M;

alter database default temporary tablespace temp_n;



col PROPERTY_VALUE for a40
col DESCRIPTION for a40
select * from database_properties;

Thursday 30 September 2010

Fix broken objects

From: http://forums.oracle.com/forums/thread.jspa?threadID=1319667&tstart=0

As sys user run:

@?/rdbms/admin/utlrp.sql

-- A check
col OBJECT_NAME for a30
select owner, object_name, object_type from dba_objects where status = 'INVALID';

Thursday 16 September 2010

UK Post

http://www.doogal.co.uk/UKPostcodes.php?Search=E1

Thursday 26 August 2010

mysql and phpmyadmin and char issue

Below is the trick that fixes the charter issue when importing data via phpmyadmin.

SET NAMES 'utf8';

Tuesday 29 June 2010

RMAN Disaster recovery, on different host

Disaster recovery (or clone db) using RMAN on different host.

- Basic version: This will restore .dbf, .ctl & .log to original location and assumes the rman backup in are in same location.
- Advance version: Marked as optional steps, restore all db files to different location and rman backup are in different location.

Summary of RMAN Disaster recovery

1. Export the SID
2. Create the folders [?dump, oradata, arch]
3. Startup nomount
4. Restore spfile
5. (optional) Change the .ctl + archive location, using pfile
6. Restore control file
7. Force mount the database
8. (optional) Catalog the backup file
9. (optional) Rman 'set newname' for restore file
10. restore database;
11. (optional) rename datafiles
12. recover database;
13. alter database open resetlogs;
14. Take a new backup of database


1. Export the SID

$ export ORACLE_SID=PRDB1

2. Create the folders [?dump, oradata, arch]

mkdir /u01/oracle/admin/PRDB1
mkdir /u01/oracle/admin/PRDB1/adump
mkdir /u01/oracle/admin/PRDB1/bdump
mkdir /u01/oracle/admin/PRDB1/cdump
mkdir /u01/oracle/admin/PRDB1/udump

mkdir /u01/oracle/oradata/PRDB1
mkdir /u11/oracle/oradata/PRDB1
mkdir /u21/oracle/oradata/PRDB1
mkdir /u31/oracle/arch_PRDB1


3. Startup nomount

$ rman target /

RMAN> startup nomount;

-- Will give you error, and say can't open initPRDB1.ora


4. Restore spfile

RMAN> restore spfile from '/mnt/restore/PRDB1_cf_c-1795524320-20100511-00';


5. (optional) Change the .ctl + archive location, using pfile

$ cd $ORACLE_HOME/dbs
$ strings spfilePRDB1.ora > initPRDB1.ora
$ mv spfilePRDB1.ora xxspfilePRDB1.oraxx
RMAN> shutdown immediate;
RMAN> startup nomount;

-- Modify the *.control_files and *.log_arc parameters (e.g. all go to /u01)


6. Restore control file

RMAN> restore controlfile from '/mnt/restore/PRDB1_cf_c-1795524320-20100511-00';


7. Force mount the database

RMAN> startup force mount;


8. (optional) Catalog the backup file

RMAN> catalog start with '/mnt/restore';


9. (optional) RMAN 'set newname' for restore file, restore to different location, needs to be done before the restore command.

set line 150
set pagesize 100
col NEW_FILE_NAME for a100
select 'set newname for datafile ' || FILE_ID || ' to ' || ''''|| FILE_NAME || ''';'
as NEW_FILE_NAME from dba_data_files;

select 'set newname for tempfile ' || FILE_ID || ' to ' || ''''|| FILE_NAME || ''';'
as NEW_FILE_NAME from dba_temp_files;


run {
set newname for datafile 1 to '/u31/oracle/oradata/PRDB1/system01.dbf';
set newname for datafile 2 to '/u31/oracle/oradata/PRDB1/undotbs01.dbf';
...
set newname for datafile 9 to '/u31/oracle/oradata/PRDB1/PRDB1_BLOB_DATA_02.dbf';
set newname for datafile 10 to '/u31/oracle/oradata/PRDB1
...
set newname for datafile 19 to '/u31/oracle/oradata/PRDB1/PRDB1_BLOB_DATA_11.dbf';

set newname for tempfile 1 to '/u31/oracle/oradata/PRDB1/temp01.dbf';

restore database;
}


10. Restore database

RMAN> restore database;


11. (optional) rename datafiles, Use below to restore to different location, needs to be done before the recover command.

set line 150
set pagesize 100
col RENAME_SQL for 150
-- data files
select 'alter database rename file '''|| NAME || ''' to ' || ''''|| NAME || ''';'
as RENAME_SQL from v$datafile;

-- redo logs
select 'alter database rename file '''|| NAME || ''' to ' || ''''|| NAME || ''';'
as RENAME_SQL from v$tempfile;

-- temp files
select 'alter database rename file ''' || lf.MEMBER || ''' to ''' || lf.MEMBER || ''';'
as RENAME_SQL from v$logfile lf, v$log l where l.group# = lf.group#;


-- Run above output via SqlPLus session
...
...
alter database rename file '/u02/oracle/oradata/PRDB1/redo02.log'
to '/u01/oracle/oradata/PRDB1/redo02.log';
alter database rename file '/u31/oracle/oradata/PRDB1/redo03.log'
to '/u01/oracle/oradata/PRDB1/redo03.log';


12. Recover database

RMAN> recover database;

-- Will give error since can't find 'unable to find archive log'


13. Open database, reset log

RMAN> alter database open resetlogs;


14. Take a new backup of database

RMAN> backup database;




Reference
=========
Below sites came useful in doing this (Backup and Recovery Reference, chap RESET DATABASE)
http://users.telenet.be/oraguy.be/make_a_clone_of_your_database_1.htm
http://www.oracle-base.com/articles/9i/DuplicateDatabaseUsingRMAN9i.php
http://kamranagayev.wordpress.com/2010/03/29/rman-video-tutorial-series-performing-disaster-recovery-with-rman/
http://download-uk.oracle.com/docs/cd/B19306_01/backup.102/b14191/rcmtroub004.htm