Search This Blog

Tuesday, February 28, 2012

Flashback archive (Oracle 11g)

In Oracle 11g, you have the possibility to use flashback archive. This feature allow you to keep track of data change on specific table (used by your application for example).

Here, we will use this feature to keep track of historical data on transaction on specific table.

Fisrt, we need to create a tablespace (TBS_FBARC) that will store these data:

CREATE TABLESPACE TBS_FBARC DATAFILE 
  '/u01/datafile/tbs_fbarc_01.dbf' SIZE 10m AUTOEXTEND ON NEXT 8K MAXSIZE 5120M,
  '/u01/datafile/tbs_fbarc_02.dbf' SIZE 10M AUTOEXTEND ON NEXT 8K MAXSIZE 5120M
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;


Then, we create the flashback archive, specify what tablespace to use, the retention time to keep historical data and grant rights on the application user (APPUSR) to use it.
CREATE FLASHBACK ARCHIVE DEFAULT FBARC
TABLESPACE TBS_FBARC
RETENTION 3 DAY;

alter flashback archive FBARC set default;
grant flashback archive on FBARC to APPUSR;


We can now add tables:
alter table APPUSR.TABLE1 flashback archive FBARC;
alter table APPUSR.TABLE2 flashback archive FBARC;


If you want (or need) to remove this feature for a table:
alter table APPUSR.TABLE2 NO flashback archive;


To check what table(s) are in the flashback archive, you need to query the table DBA_FLASHBACK_ARCHIVE_TABLES.

Attention, the UNDO tablespace has to be monitored closely, if the flashback archive tablespace is too small or the retention too big, it will be filled really quickly!!

You can monitor the space used by each tables using flashback archive with this query:
 SELECT T.Owner_name,
         T.Table_name,
         S.Tablespace_name,
         SUM (S.Bytes)/1024/1024 Total_space
    FROM Sys.Dba_flashback_archive_tables T, Sys.Dba_segments S
   WHERE     T.Owner_name = S.Owner
         AND T.Flashback_archive_name = 'FBARC'
         AND S.Segment_name LIKE 'SYS_FBA%' || SUBSTR (Archive_table_name,
                           INSTR (Archive_table_name, '_', -1, 1) + 1,
                           LENGTH (Archive_table_name))
GROUP BY T.Owner_name, T.Table_name, S.Tablespace_name
ORDER BY 4 desc;

Supplemental documentation can be found here:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25518/adfns_flashback.htm

I will resume this at a later stage and add the most important information on this post.

Thursday, February 23, 2012

TNS-12535: TNS:operation timed out


Specific to Oracle 11G

If you see the errors in the alert logfile :
*********************************************************************** 

Fatal NI connect error 12170. 

  VERSION INFORMATION: 
        TNS for Linux: Version 11.2.0.2.0 - Production 
        Oracle Bequeath NT Protocol Adapter for Linux: Version 11.2.0.2.0 - Production 
        TCP/IP NT Protocol Adapter for Linux: Version 11.2.0.2.0 - Production 
  Time: 11-DEC-2011 15:08:18 
  Tracing not turned on. 
  Tns error struct: 
    ns main err code: 12535 

TNS-12535: TNS:operation timed out 
    ns secondary err code: 12560 
    nt main err code: 505 

TNS-00505: Operation timed out 
    nt secondary err code: 110 
    nt OS err code: 0


It may be due to the usage of Oracle Grid Control. To fix the issue you have to add the 2 lines below in your sqlnet.ora

SQLNET.ENCRYPTION_TYPES_SERVER=(3DES168)
SQLNET.ENCRYPTION_SERVER=REQUIRED

SHUTDOWN: waiting for active calls to complete

1. connect to SYS user with new terminal window
SQL> conn / sysdba
Connected TO idle instance.


2. shutdown database with ABORT option
SQL> shutdown abort;
ORACLE instance shut down.


3. open database for normal shutdown with RESTRICT option
SQL> startup restrict
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 788496 bytes
Variable Size 149682160 bytes
DATABASE Buffers 16777216 bytes
Redo Buffers 524288 bytes
DATABASE mounted.
DATABASE opened. 


4. now shutdown database with NORMAL option
SQL> shutdown normal;
DATABASE closed.
DATABASE dismounted.
ORACLE instance shut down.


5. You can now restart your instance properly.

Wednesday, February 22, 2012

YUM / RPM cheat


As root (or sudo):

YUM


To update your system:
yum update

To install a package:
yum install PACKAGE

To search a package:
yum search PACKAGE

To have more information for a specific package (version, architecture, etc):
yum info PACKAGE

To clean a "fucked up" yum conf:
yum clean all


RPM


What package "hold" a command
rpm -qf CMD

List packages
rpm -qa

Details of the package
rpm -qi PACKAGE

Erase a package. Give dependencies that block PACKAGE to be removed too)
rpm -e PACKAGE

Details of what provides a package
rpm -q --provides PACKAGE

Upgrade or install a package
rpm -Uvh PACKAGE

Upgrade a package (if already installed)
rpm -F PACKAGE

ORA-00059: maximum number of DB_FILES exceeded


If you have this error in your alertSID.log:
ERROR at line 1:
ORA-00059: maximum number of DB_FILES exceeded

You have to increase the number of file allowed for the database. The instance has to be restarted:
SQL> SHOW parameter db_files
--> 1500

SQL> ALTER system SET db_files = 3000 scope = BOTH;
SQL> shutdown immediate
SQL> startup
SQL> SHOW parameter db_files
--> 3000

Configure Oracle Enterprise Linux for an Oracle 11g install


Step by step Oracle database 11g install (Part 1)

Install Centos 6 (or any RHEL 6)

(for Unbreakable Enterprise Linux User)
as root:
If you don't have a ULN subscription you may prefer to remove up2date and access repos manually via yum instead:
yum remove up2date


add the repo in yum:
cd /etc/yum.repo.d 
wget http://public-yum.oracle.com/public-yum-ol6.repo
in /etc/yum.repos.d/public-yum-ol6.repo, the following must be with enabled=1 (the other at 0):
[ol6_latest]
[ol6_addons]
[ol6_UEK_latest]

Search for the latest Oracle software:
yum search oracle


Auto-configure your new system (users, group, pre-require packages, etc)
yum install oracle-rdbms-server-11gR2-preinstall.i686


if you have this error:
[Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

It's because the Oracle gpg key for their repo hasn't been installed yet.

Do it and restart the install process
wget https://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

or
wget --no-check-certificate https://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

Reboot, your system is ready to have Oracle 11g installed. Di it here :)