顯示具有 oracle 標籤的文章。 顯示所有文章
顯示具有 oracle 標籤的文章。 顯示所有文章

2018年6月5日 星期二

Oracle LogMiner


SUPPLEMENTAL_LOG_DATA

查詢

select SUPPLEMENTAL_LOG_DATA_MIN min,
       SUPPLEMENTAL_LOG_DATA_PK  pk,
       SUPPLEMENTAL_LOG_DATA_UI  ui,
       SUPPLEMENTAL_LOG_DATA_FK  fk,
       SUPPLEMENTAL_LOG_DATA_ALL "all"
  from v$database;

開 min

alter database add supplemental log data ;

關閉

alter database drop supplemental log data ;


删除SUPPLEMENTAL LOG DATA需要先删除其他的追加日志,可以通过查看v$database检查是否还有没有关闭的

select SUPPLEMENTAL_LOG_DATA_ALL
,SUPPLEMENTAL_LOG_DATA_FK
,SUPPLEMENTAL_LOG_DATA_MIN
,SUPPLEMENTAL_LOG_DATA_PK
,SUPPLEMENTAL_LOG_DATA_UI from v$database;


可以先删除某些键值的追加日志,执行例如:

ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;
ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS;
ALTER DATABASE DROP SUPPLEMENTAL LOG DATA;

ref :
https://hk.saowen.com/a/0a25fb4bedb5e7be62acc321e6c473ef20e7773fb9349bd1c1054e808d78311d

http://blog.51cto.com/sugarlovecxq/1693092 Oracle中的补充日志(supplemental log)


確認是否在 archived mode


select log_mode from v$database;

起始安裝


run as SYSDBA

$ORACLE_HOME/rdbms/admin/dbmslm.sql

$ORACLE_HOME/rdbms/admin/dbmslmd.sql





在本機的場合


execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168869.dbf',options=>dbms_logmnr.new);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168870.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168871.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168872.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168873.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168874.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168875.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168876.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168877.dbf',options=>dbms_logmnr.addfile);


第一個用 new 之後用 addfile

然後可以在 V_$logmnr_logs 看到剛才放進去的 log

然後
execute dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);

然後可以在 V_logmnr_contents 看到剛剛產生的結果

然後

select operation,table_name from v_$logmnr_contents where operation='DELETE' and table_name='TRACE_LOG';

把需要的資料轉存成table (只有這個session 可以看到 V_$logmnr_* 的內容)

然後

execute dbms_logmnr.end_logmnr;

釋放資源


在別機的場合


CREATE DIRECTORY utlfile AS '/rman_disk/logminer/utlfile';
alter system set utl_file_dir='/rman_disk/logminer/utlfile' scope=spfile;

EXECUTE dbms_logmnr_d.build(dictionary_filename => 'dictionary.ora', dictionary_location =>'/rman_disk/logminer/utlfile');

起始 UTL_FILE 參數位置 沒在 init 時設好的話可能會看到

ERROR at line 1:
ORA-01308: initialization parameter utl_file_dir is not set
ORA-06512: at "SYS.DBMS_LOGMNR_INTERNAL", line 3669
ORA-06512: at "SYS.DBMS_LOGMNR_INTERNAL", line 3747
ORA-06512: at "SYS.DBMS_LOGMNR_D", line 12
ORA-06512: at line 1

--可以用 show parameter UTL_FILE 確認
-- utl_file_dir 是 init param , 不能用 alter system both 設定

SQL> alter system set utl_file_dir='/rman_disk/logminer/utlfile' scope=both;  
alter system set utl_file_dir='/rman_disk/logminer/utlfile' scope=both
                 *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified




然後在 start 的時候用

EXECUTE dbms_logmnr.start_logmnr(dictfilename=>'D:\oracle\oradata\practice\LOGMNR\dictionary.ora');




ref:

图解Oracle Logminer配置使用

https://docs.oracle.com/cd/E18283_01/appdev.112/e16760/d_logmnrd.htm   DBMS_LOGMNR_D

Oracle SCN 轉 Timestamp

REF:  http://www.eygle.com/archives/2007/01/scntimestamp_function.html


首先通过dbms_flashback.get_system_change_number 可以获得系统当前的SCN值:
SQL> col scn for 9999999999999
SQL> select dbms_flashback.get_system_change_number scn from dual;
SCN
--------------
8908390522972
通过scn_to_timestamp函数可以将SCN转换为时间戳:
SQL> select scn_to_timestamp(8908390522972) scn from dual;
SCN
---------------------------------------------------------------------------
05-JAN-07 10.56.30.000000000 AM
再通过timestamp_to_scn可以将时间戳转换为SCN:
SQL> select timestamp_to_scn(scn_to_timestamp(8908390522972)) scn from dual;
SCN
--------------
8908390522972
通过这两个函数,最终Oracle将SCN和时间的关系建立起来,在Oracle10g之前,是没有办法通过函数转换得到SCN和时间的对应关系的,一般可以通过logmnr分析日志获得。
但是这种转换要依赖于数据库内部的数据记录,对于久远的SCN则不能转换,请看以下举例:
SQL> select min(FIRST_CHANGE#) scn,max(FIRST_CHANGE#) scn from v$archived_log;
SCN SCN
------------------ ------------------
8907349093953 8908393582271
SQL> select scn_to_timestamp(8907349093953) scn from dual;
select scn_to_timestamp(8907349093953) scn from dual
*
ERROR at line 1:
ORA-08181: specified number is not a valid system change number
ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1
ORA-06512: at line 1

SQL> select scn_to_timestamp(8908393582271) scn from dual;
SCN
---------------------------------------------------------------------------
05-JAN-07 11.45.50.000000000 AM
-The End-

2017年12月1日 星期五

DPIMP做到一半死掉


https://shanojkumar.wordpress.com/2013/05/29/ora-31626-job-does-not-exist-and-how-to-cleanup-orphaned-datapump-jobs-in-dba_datapump_jobs/

http://blog.oracle48.nl/wordpress/killing-and-resuming-datapump-expdp-and-impdp-jobs/

https://dbatricksworld.com/how-to-kill-oracle-datapump-export-job/

SQL> DECLARE
h1 NUMBER;
BEGIN
h1:=DBMS_DATAPUMP.ATTACH(‘SYS_EXPORT_FULL_01‘,’SYSTEM‘);
DBMS_DATAPUMP.STOP_JOB (h1,1,0);
END;
/

試著 attach 回去然後再stop / start

如果一直吐 ORA-31626:  Job does not exist 那就只能幹掉他

看還有沒有在跑
select * from dba_datapump_jobs;

找MAIN TABLE 然後 DROP掉
--SELECT o.status, o.object_id, o.object_type,
--o.owner||'.'||object_name "OWNER.OBJECT"
--FROM dba_objects o, dba_datapump_jobs j
--WHERE o.owner=j.owner_name AND o.object_name=j.job_name
--AND j.job_name NOT LIKE 'BIN$%' ORDER BY 4,2;

然後清除轉一半的東西重做

select object_type,count(object_type) as c from sys.all_objects where owner='{SCHEMA_NAME}' group by objecT_type order by 2

2017年10月30日 星期一

oracle LOGICAL_STANDBY_DB

與 physical standby db 的差異

http://www.dba-oracle.com/t_difference_logical_physical_standby_database.htm

In  Oracle Data Guard you, Oracle transfers data from the main database to a standby database, and in case of failures, Oracle will switch over to the standby database.  We have two ways to create a standby database, logical standby and physical standby:
Physical standby differs from logical standby:
  • Physical standby schema matches exactly the source database.
  • Archived redo logs and FTP'ed directly to the standby database which is always running in "recover" mode.  Upon arrival, the archived redo logs are applied directly to the standby database.
Logical standby is different from physical standby:
  • Logical standby database does not have to match the schema structure of the source database.
     
  • Logical standby uses LogMiner techniques to transform the archived redo logs into native DML statements (insert, update, delete).  This DML is transported and applied to the standby database.
     
  • Logical standby tables can be open for SQL queries (read only), and all other standby tables can be open for updates.
     
  • Logical standby database can have additional materialized views and indexes added for faster performance.
Installing Physical standbys offers these benefits:
  • An identical physical copy of the primary database
  • Disaster recovery and high availability
  • High Data protection
  • Reduction in primary database workload
  • Performance Faster
Installing Logical standbys offer:
  • Simultaneous use for reporting, summations and queries
  • Efficient use of standby hardware resources
  • Reduction in primary database workload
  • Some limitations on the use of certain datatypes

For more complete differences between logical and physical standby databases, see the book "Oracle Data Guard", by Bipul Kumar.


Create Logical Standby DB


需要用 PK 或 unique index 識別唯一值

在 DBA_LOGSTDBY_NOT_UNIQUE 可以查到無法識別出的表


2017年8月14日 星期一

Oracle PatchSet

Oracle补丁集的命名规则,那就是:

p<patch number>_<release number>_<os>.zip

oracle 9208 patch:

p4547809_92080_AIX64-5L.zip
p4547809_92080_AXP.zip
p4547809_92080_HP64.zip
p4547809_92080_HPUX-IA64.zip
p4547809_92080_LINUX-S390.zip
p4547809_92080_LINUX.zip
p4547809_92080_Linux-IA64.zip
p4547809_92080_Linux-x86-64.zip
p4547809_92080_MVS.zip
p4547809_92080_SOLARIS.zip
p4547809_92080_SOLARIS64.zip
p4547809_92080_TRU64.zip
p4547809_92080_WINNT.zip
p4547809_92080_WINNT64.zip

oracle 10.2.0.4 patch:

p6810189_10204_AIX5L.zip
p6810189_10204_HPUX-IA64.zip
p6810189_10204_HPUX-64.zip
p6810189_10204_Solaris-64.zip
p6810189_10204_Linux-x86-64.zip
p6810189_10204_Linux-x86.zip
p6810189_10204_Win32.zip
p6810189_10204_MSWIN-x86-64.zip

oracle 10.2.0.3 patch:

p5337014_10203_AIX64-5L.zip
p5337014_10203_HP64.zip
p5337014_10203_IBMPower.zip
p5337014_10203_LINUX.zip
p5337014_10203_Linux-IA64.zip
p5337014_10203_Linux-x86-64.zip
p5337014_10203_MSWIN-x86-64.zip
p5337014_10203_MVS.zip
p5337014_10203_SOLARIS64.zip
p5337014_10203_WINNT.zip
p5337014_10203_WINNT64.zip






Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit)

10201_database_win32.zip
10201_client_win32.zip
10201_clusterware_win32.zip
10201_gateways_win32.zip

oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (x64)

102010_win64_x64_database.zip
102010_win64_x64_client.zip
102010_win64_x64_clusterware.zip

Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Linux x86

10201_database_linux32.zip
10201_client_linux32.zip
10201_gateways_linux32.zip

Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for linux x86-64

10201_database_linux_x86_64.cpio.gz
10201_client_linux_x86_64.cpio.gz
10201_clusterware_linux_x86_64.cpio.gz
10201_gateways_linux_x86_64.cpio.gz

Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for AIX5L

10gr2_aix5l64_database.cpio.gz
10gr2_aix5l64_client.cpio.gz
10gr2_aix5l64_cluster.cpio.gz
10gr2_aix5l64_gateways.cpio.gz

Oracle Database 10g Release 2 (10.2.0.2) Enterprise/Standard Edition for Solaris Operating System (x86)

10202_database_solx86.zip
10202_client_solx86.zip
10202_clusterware_solx86.zip

Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Solaris Operating System (x86-64)

10201_database_solx86_64.zip
10201_client_solx86_64.zip
10201_clusterware_solx86_64.zip


Oracle9i Database Release 2 Enterprise/Standard/Personal Edition for Windows NT/2000/XP

92010NT_Disk1.zip
92010NT_Disk2.zip
92010NT_Disk3.zip

Oracle9i Database Release 2 Enterprise/Standard/Personal/Client Edition for Windows XP 2003/Windows Server 2003 (64-bit)

92021Win64_Disk1.zip
92021Win64_Disk2.zip

Oracle9i Database Release 2 Enterprise/Standard Edition for Intel Linux

ship_9204_linux_disk1.cpio.gz
ship_9204_linux_disk2.cpio.gz
ship_9204_linux_disk3.cpio.gz

Oracle9i Database Release 2 (9.2.0.4) Enterprise/Standard Edition for Linux x86-64

amd64_db_9204_Disk1.cpio.gz
amd64_db_9204_Disk2.cpio.gz
amd64_db_9204_Disk3.cpio.gz

Oracle9i Database Release 2 Enterprise/Standard Edition for AIX - Based 4.3.3 Systems (64-bit)

server_9201_AIX64_Disk1.cpio.gz
server_9201_AIX64_Disk2.cpio.gz
server_9201_AIX64_Disk3.cpio.gz
server_9201_AIX64_Disk4.cpio.gz

Oracle9i Database Release 2 Enterprise/Standard Edition for AIX- Based 5L Systems

A99331-01.zip
A99331-02.zip
A99331-03.zip
A99331-04.zip

Oracle9i Database Release 2 Enterprise/Standard Edition for Sun SPARC Solaris (32-bit)

92010Sol_Disk1.cpio.gz
92010Sol_Disk2.cpio.gz
92010Sol_Disk3.cpio.gz

Oracle9i Database Release 2 Enterprise/Standard Edition for Sun SPARC Solaris (64-bit)

solaris64_9.2.0.1.0.Disk1.cpio.gz
solaris64_9.2.0.1.0.Disk2.cpio.gz
solaris64_9.2.0.1.0.Disk3.cpio.gz


史上最全Oracle PSU,SPU(CPU),Bundle Patches 和 Patchsets 补丁号码快速参考
本文来自:itpux技术网
                                                Patchsets               
l12.1.0.2 (12.1.0.2.0                 PATCH SET FOR ORACLE DATABASE SERVER)
17694377
11.2.0.4 (11.2.0.4.0                 PATCH SET FOR ORACLE DATABASE SERVER)
13390677
11.2.0.3 (11.2.0.3.0                 PATCH SET FOR ORACLE DATABASE SERVER)
10404530
11.2.0.2 (11.2.0.2.0                 PATCH SET FOR ORACLE DATABASE SERVER)
10098816
11.1.0.7 (11.1.0.7.0                 PATCH SET FOR ORACLE DATABASE SERVER)
6890831
10.2.0.5 (10.2.0.5                 PATCH SET FOR ORACLE DATABASE SERVER)
8202632
d10.2.0.4 (10.2.0.4.0                 PATCH SET FOR ORACLE DATABASE SERVER)
6810189
e10.2.0.3 (10.2.0.3                 PATCH SET FOR ORACLE DATABASE SERVER)
5337014
10.2.0.2 (10.2.0.2                 PATCH SET FOR ORACLE DATABASE SERVER)
4547817
10.1.0.5 (10.1.0.5                 PATCH SET FOR ORACLE DATABASE SERVER)
4505133
10.1.0.4 (10.1.0.4                 PATCH SET FOR ORACLE DATABASE SERVER)
4163362
10.1.0.3 (10.1.0.3                 PATCH SET FOR ORACLE DATABASE SERVER)
3761843
                 9.2.0.8 (9.2.0.8 PATCH SET FOR ORACLE DATABASE SERVER)
4547809
                 9.2.0.7 (9.2.0.7 PATCH SET FOR ORACLE DATABASE SERVER)
4163445
                 9.2.0.6 (9.2.0.6 PATCH SET FOR ORACLE DATABASE SERVER)
3948480
                 9.2.0.5 (ORACLE 9I DATABASE SERVER RELEASE 2 – PATCH SET 4                 VERSION 9.2.0.5.0)
3501955
                 9.2.0.4 (9.2.0.4 PATCH SET FOR ORACLE DATABASE SERVER)
3095277
                 9.2.0.3 (9.2.0.3 PATCH SET FOR ORACLE DATABASE SERVER)
2761332
                 9.2.0.2 (9.2.0.2 PATCH SET FOR ORACLE DATABASE SERVER)
2632931
                 9.0.1.5 (9.0.1.5 PATCHSET)
3301544
                 9.0.1.4 (9.0.1.4 PATCH SET FOR ORACLE DATABASE SERVER)
2517300
                 9.0.1.3 (9.0.1.3. PATCH SET FOR ORACLE DATA SERVER)
2271678
                 8.1.7.4 (8.1.7.4 PATCH SET FOR ORACLE DATA SERVER)
2376472
                 8.1.7.3 (8.1.7.3 PATCH SET FOR ORACLE DATA SERVER)
2189751
                 8.1.7.2 (8.1.7.2.1 PATCH SET FOR ORACLE DATA SERVER)
1909158

2017年2月8日 星期三

AIX create Oracle instance 問題(AIO未開)

ORA-12547: TNS:lost contact

根據 sqlnet.log

Fatal NI connect error 12547, connecting to:
 (DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/oracle/10g/product/10.2.0/db/bin/oracle)(ARGV0=oraclehisspu)(ARGS='(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))')(DETACH=NO))(CONNECT_DATA=(CID=(PROGRAM=sqlplus@f7n4)(HOST=f7n4)(USER=oracle10))))

  VERSION INFORMATION:
        TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production
        TCP/IP NT Protocol Adapter for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production
        Oracle Bequeath NT Protocol Adapter for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production
  Time: 07-FEB-2017 12:01:33
  Tracing not turned on.
  Tns error struct:
    ns main err code: 12547
    TNS-12547: TNS:lost contact
    ns secondary err code: 12560
    nt main err code: 517
    TNS-00517: Lost contact
    nt secondary err code: 32


然後使用 sqlplus 時出現

exec(): 0509-036 Cannot load program oraclenam because of the following errors:
        0509-130 Symbol resolution failed for /usr/lib/libc.a[aio_64.o] because:
        0509-136   Symbol kaio_rdwr64 (number 1) is not exported from
                   dependent module /unix.
        0509-136   Symbol listio64 (number 2) is not exported from
                   dependent module /unix.
        0509-136   Symbol acancel64 (number 3) is not exported from
                   dependent module /unix.
        0509-136   Symbol iosuspend64 (number 4) is not exported from
                   dependent module /unix.
        0509-136   Symbol aio_nwait (number 5) is not exported from
                   dependent module /unix.
        0509-136   Symbol aio_nwait64 (number 6) is not exported from
                   dependent module /unix.
        0509-136   Symbol aio_nwait_timeout (number 7) is not exported from
                   dependent module /unix.
        0509-136   Symbol aio_nwait_timeout64 (number 8) is not exported from
                   dependent module /unix.
        0509-026 System error: Error 0
        0509-192 Examine .loader section symbols with the
                 'dump -Tv' command.

根據
Symbol resolution failed for /usr/lib/libc.a[aio_64.o] 
問題是出在AIX 的 AIO 沒有啟用 (在跑 LDAP時沒有用到所以沒有問題 ORACLE需要)

根據

0509-130 Symbol resolution failed for /usr/lib/libc.a[aio_64.o]
This error occurs because the Asynchronous I/O are not available.
# lsattr -El aio0
autoconfig defined STATE to be configured at system restart True
fastpath enable State of fast path True
kprocprio 39 Server PRIORITY True
maxreqs 4096 Maximum number of REQUESTS True
maxservers
10 MAXIMUM number of servers per cpu True
minservers 1 MINIMUM number of servers True
You must make the Asynchronous I/O available using smitty
# smitty chgaio
Change this item
STATE to be configured at system restart available
IMPORTANT: Changes will become effective at next system restart
For configure Asynchronous I/O now use:
# smitty aio
Configure Defined Asynchronous I/O
Checking aio0 again
# lsattr -El aio0
autoconfig available STATE to be configured at system restart True
fastpath   enable    State of fast path                       True
kprocprio  39        Server PRIORITY                          True
maxreqs    4096      Maximum number of REQUESTS               True
maxservers
10        MAXIMUM number of servers per cpu        True
minservers 1         MINIMUM number of servers                True
 
另外 依據

使用操作系统命令开启异步I/O(1)确认所需的bos.rte.aio是否安装妥当
# lslpp -l bos.rte.aio
  Fileset                      Level  State      Description         
  ----------------------------------------------------------------------------
Path: /usr/lib/objrepos
  bos.rte.aio               5.3.0.62  COMMITTED  Asynchronous I/O Extension

(2)使用如下命令开启AIX操作系统的异步I/O
# mkdev -l aio0
aio0 Available

# chdev -P -l aio0 -a autoconfig='available'
aio0 changed

依據

The ‘minservers’ setting (10) is the total number of aioserver kernel threads that start at boot – this is not a per CPU or per logical CPU value.
The ‘maxservers’ setting (20) is the maximum number of aioserver  per CPU or per logical CPU value.
The ‘maxreqs’ setting (4096) is the maximum number of outstanding or pending requests that the kernel will allow at any one time.
The default value for the minimum number of servers is 1. The default value for the maximum number of servers is 10. These values are usually too low to run Oracle Database on large systems with 4 CPUs or more, if you are not using kernelized AIO( for raw devices).

2017年1月20日 星期五

oracle enable / disable archive_n

相關參數
log_archive_dest_state_n
log_archive_dest_n

alter system set log_archive_dest_state_n=defer scope=both;

alter system set log_archive_dest_state_n=enable scope=both;

可以用  ALTER SYSTEM ARCHIVE LOG CURRENT 出清現有 redo

參考
https://docs.oracle.com/cd/B14117_01/server.101/b10755/initparams102.htm

LOG_ARCHIVE_DEST_STATE_n = { alternate | reset | defer | enable }


The LOG_ARCHIVE_DEST_STATE_n parameters (wheren = 1, 2, 3, ... 10) specify the availability state of the corresponding destination. The parameter suffix (1 through 10) specifies one of the ten corresponding LOG_ARCHIVE_DEST_n destination parameters.
Values:
  • enabled
    Specifies that a valid log archive destination can be used for a subsequent archiving operation (automatic or manual). This is the default.
  • defer
    Specifies that valid destination information and attributes are preserved, but the destination is excluded from archiving operations until re-enabled.
  • alternate
    Specifies that a log archive destination is not enabled but will become enabled if communications to another destination fail.
The LOG_ARCHIVE_DEST_STATE_n parameters have no effect on the ENABLE state for the LOG_ARCHIVE_DEST or LOG_ARCHIVE_DUPLEX_DEST parameters.


The V$ARCHIVE_DEST dynamic performance view shows values in use for the current session. The DEST_ID column of that view corresponds to the archive destination suffix n.


2016年10月14日 星期五

be exported in conventional path

Table *** will be exported in conventional path.

在 EXP 時指定了  direct =y

根據  https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::p11_question_id:968789918647


A direct path export should not be considered the converse of a direct path load using SQLLDR (for those of you familiar with that option). A direct path export does not read directly from the datafiles and write to the DMP file. SQLLDR does write directly to the datafiles from the DAT files. Export in direct path mode simply bypasses the SQL evaluation buffer (where clause processing, column formatting and such). 90% of the path is the same, EXP is still reading buffers into the buffer cache, doing the same consistent read processing and so on. 

The speedup of the direct path export can be large however. The 10% of the processing that it cuts out, accounts for a much larger percentage of the run-time. For example, I have just exported about 100meg of data, and 1.2 million records. The direct path export took about one minute. The conventional path export on the other hand took three minutes. There is unfortunately no corresponding 'direct path import'. Import uses conventional SQL to insert the data back into tables. SQLLDR is still the way to go for high performance data loads. 

It should be noted that in direct path mode, you cannot use the QUERY= parameter to select a subset of rows. This makes sense given that DIRECT=Y is simply a way to bypass the SQL evaluation buffer and that is where the where clause processing would normally take place. 



2016年8月26日 星期五

Oracle Query Alert Log fvia SQL

http://www.dba-oracle.com/t_11g_dbgalertext_alert_log_sql.htm

http://www.dba-oracle.com/t_oracle_alert_log_sql_external_tables.htm


11可以查 X$DBGALERTEXT

11以前要用外部文件的方式

create directory BDUMP as '/u01/app/oracle/admin/mysid/bdump';

create table 
   alert_log ( msg varchar2(80) )
organization external (
   type oracle_loader
   default directory BDUMP
   access parameters (
      records delimited by newline
   )
   location('alrt_mysid.log')
)
reject limit 1000;


Oracle 8i DDL Trigger

https://docs.oracle.com/cd/A87860_01/doc/appdev.817/a76939/toc.htm

https://docs.oracle.com/cd/A87860_01/doc/appdev.817/a76939/adg13trg.htm#6366

https://docs.oracle.com/cd/A87860_01/doc/appdev.817/a76939/adg14evt.htm#998000

https://docs.oracle.com/cd/A87860_01/doc/appdev.817/a76939/adg14evt.htm#1000872

2016年6月9日 星期四

ORACLE 過 purge

CLOB 搬移
http://www.dba-oracle.com/t_alter_table_move_index_constraint.htm


找 CLOB Column
 select table_name from dba_tab_columns where OWNEr='SCOTT' and data_type='CLOB';
  select table_name from dba_tab_columns where OWNEr='SCOTT' and data_type like '%LOB%';
  
Assuming that I have table "TEST" in USERS TableSpace

CREATE TABLE TEST
(
TEST_ID NUMBER NOT NULL,
TEST_NAME CLOB,
CONSTRAINT PK_TEST PRIMARY KEY(TEST_ID)
)
/


SQL> ALTER TABLE TEST MOVE TABLESPACE EXAMPLE;

Above command will move the table to new tablespace but will not move the CLOB segment and it will still be in original tablespace. This is because LOB data is stored outside of the table.
Check the tablespace of the CLOB column by issuing following sql.

SQL> SELECT index_name, tablespace_name
FROM user_indexes WHERE table_name = ‘TEST’;

INDEX_NAME TABLESPACE_NAME
—————————— —————-
SYS_IL0000073575C00002$$ USERS

In order to move CLOB column to different tablespace, we have to issue following command.

SQL> ALTER TABLE TEST MOVE LOB(TEST_NAME) STORE AS (TABLESPACE EXAMPLE);

In above example, TEST_NAME is the CLOB column which we want to move to new tablespace and EXAMPLE is target tablespace. Above command will successfully move LOB segments to the new tablespace. We can verify it by issuing same sql again.

SQL> SELECT index_name, tablespace_name
FROM user_indexes WHERE table_name = ‘TEST’;

INDEX_NAME TABLESPACE_NAME
—————————— —————
SYS_IL0000073575C00002$$ EXAMPLE

ORACLE parameter file (PFILE , SPFILE)

CREATE PFILE='/tmp/initoradbtst.ora.2016053102' from spfile='/oracle/10g/product/10.2.0/db/dbs/spfileoradbtst.ora';

CREATE spfile='/oracle/10g/product/10.2.0/db/dbs/spfileoradbtst.ora' from PFILE='/oracle/10g/product/10.2.0/db/dbs/initoradbtst.ora'  ;


10g 這邊只能 create pfile from spfile 或是 creare spfile form pfile

會在 ORACLE_HOME/dbs 底下先找 spfile 跟 pfile . (順序要再確認)

在啟動的時候可以指定 startup PFILE='絕對路徑';


--controll file 比較麻煩 要 recreate  . 而且 scn 不對還要 resetlog

2016年5月18日 星期三

Oracle 系統帳號


"SYS",                          
"SYSTEM",                      
"OUTLN",                        
"DBSNMP",                      
"WMSYS",                        
"ORDSYS",                      
"ORDPLUGINS",                  
"MDSYS",                        
"CTXSYS",                      
"XDB",                          
"ANONYMOUS",                    
"WKSYS",                        
"WKPROXY",                      
"ODM",                          
"ODM_MTR",                      
"OLAPSYS",                      
"HR",                          
"OE",                          
"PM",                          
"SH",                          
"QS_ADM",                      
"QS",                          
"QS_WS",                        
"QS_ES",                        
"QS_OS",                        
"QS_CBADM",                    
"QS_CB",                        
"QS_CS",                        
"SCOTT",                        
"DIP",                          
"TSMSYS",                      
"ORACLE_OCM",                  
"DMSYS",                        
"SI_INFORMTN_SCHEMA",          
"MDDATA",                      
"SYSMAN",                      
"MGMT_VIEW"



select '"'||username||'",' as c
from sys.all_users where
trunc(created) = to_date('200XXXXXX','yyyymmdd')
or
trunc(created) = to_date('20XXXXXX','yyyymmdd')
order by user_id


2016年4月27日 星期三

sqlplus 參考


直接連線

10G 以後可以

sqlplus scott/tiger@//ipアドレス:ポート番号/SID

9i
sqlplus billyv@"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.251.93.233)(PORT=1521))(CONNECT_DATA=(SID=orcl)(SERVER=dedicated)))"



密碼中有 @

sqlplus /nolog
SQL> alter user scott identified by "scott@test";
User altered.

SQL> connect scott/"scott@test";
Connected.

or
sqlplus scott/\”scott@test\”@TEST_DB


參數處理


set pagesize 0; -- 設9999的話還是會有斷行
set linesize 9999; --最小是1
set heading off;
set echo off;
set feedback off;--把 select X rows 關掉 -- 可是這樣會造成 spool 吐不出來
spool log.log
..................
spool off;

2016年3月29日 星期二

Oracle 10g CENTOS 6.4

CENTOS 6.4 裝好 選 minial desktop
因為要有桌面環境才能跑 oracle 的 UI

然後依據
http://www.cnblogs.com/mchina/archive/2013/03/08/2934473.html
http://blog.itpub.net/21256317/viewspace-776791/

關防火牆
# chkconfig iptables off
# chkconfig ip6tables off
# service iptables stop
# service ip6tables stop

關 SELinux
# vi /etc/selinux/config
修改 SELINUX=disabled
不重開的話 下 # setenforce 0


安裝需要的套件

用 yum 安裝需要的軟體
# yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat

# yum install libXp
# yum -y install libXp.i686 --setopt=protected_multilib=false
# yum -y install libXt.i686 --setopt=protected_multilib=false
# yum -y install libXtst.i686 --setopt=protected_multilib=false
裝 .i686 的軟體的時候要加 --setopt=protected_multilib=false
因為這時候系統裡面同時有 i686 跟 x64 的版本 . 套件管理系統會警告這件事

裝一下 nautilus 可以按右鍵開終端機 非必要
$ sudo yum install nautilus-open-terminal

建好 oracle10 帳號跟 dba 群組
把 oracle10 帳號的主群組設為 dba . (把原本的oracle10 群組拿掉)
用 
# id oracle10 確認
[root@db3 ~]# id oracle10
uid=500(oracle10) gid=500(dba) groups=500(dba)


把 redhat-release 換掉
# vim /etc/redhat-release
改成
redhat-4

改sysctl.conf
# vi /etc/sysctl.conf

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096

fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144

然後用 sysctl -p 載入新設定


改 limits.conf
# vi /etc/security/limits.conf  加入
oracle10  soft nproc 2047
oracle10  hard nproc 16384
oracle10  soft nofile 1024
oracle10  hard nofile 65536


改 login
# vi /etc/pam.d/login  加入
session required /lib64/security/pam_limits.so
session required pam_limits.so




改/etc/profile
# vi /etc/profile

if [ $USER = "oracle10" ]; then
    if [ $SHELL = "/bin/ksh" ]; then
        ulimit -p 16384
        ulimit -n 65536
    else
        ulimit -u 16384 -n 65536
    fi
fi 

改 /ets/hosts
新增自己的ip跟別名
192.168.200.33  db3 


建立 oracle 安裝資料夾
# mkdir /oracle10
# mkdir /oracle10/102
# chown -R oracle10:dba /oracle10


** 以 oracle10 身份登入設定環境變數
$ cd /home/oracle
$ vi .bash_profile

ORACLE_BASE=/oracle10 
ORACLE_HOME=$ORACLE_BASE/102
ORACLE_SID=hisspn
LD_LIBRARY_PATH=$ORACLE_HOME/lib
PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH PATH

重讀設定檔
$ source /home/oracle10/.bash_profile

上傳並解壓縮安裝檔
$ unzip 10201_database_linux_x86_64.cpio.gz
$ cpio -idmv < 10201_database_linux_x86_64.cpio

設定 huge_tlb
# id oracle
uid=500(oracle10) gid=500(dba) groups=500(dba)
echo "500" > /proc/sys/vm/hugetlb_shm_group

開始安裝
$ cd database
$ export LANG=en_US   <-- 其他語系顯示的時候字型可能會爛掉
$ ./runInstaller

如果看不到跳出來的視窗,用 root 下
# export DISPLAY=:0.0
# xhost +


===================
錯誤
Exception in ...... /lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory
# yum -y install libXp.i686
Exception in ...... /lib/i386/libawt.so: libXt.so.6: cannot open shared object file: No such file or directory
# yum -y install libXt.i686
Exception in ...... /lib/i386/libawt.so: libXtst.so.6: cannot open shared object file: No such file or directory
# yum -y install libXtst.i686
====================













安裝到一半會出現這個錯誤 聽說是bug 可以不用管它
Error in invoking target 'collector' of makefile '/oracle10/102/sysman/lib/ins_emdb.mk'.



開一個 root shell 下
/oracle10/oraInventory/orainstRoot.sh
/oracle10/102/root.sh




=======================================
問題處理
ORA-27125:unable to create shared memory segment
# id oracle10
uid=500(oracle10) gid=500(dba) groups=500(dba)
echo "500" >/proc/sys/vm/hugetlb_shm_group
=======================================

安裝 patch 
裝完 oracle 軟體之後如果沒建資料庫應該都是關著的
SQL> SHUTDOWN IMMEDIATE
$ emctl stop dbconsole
$ isqlplusctl stop
$ lsnrctl stop

$ unzip p8202632_10205_Linux-x86-64.zip
$ cd Disk1
$ ./runInstaller -ignoreSysPrereqs   <-- 等等會抱怨 OS 版本不對







再開一個 root shell 來跑
會問是否要覆蓋現有檔案


安裝完成



如果有先開好的 instance 的話

a. 更新数据字典

$ sqlplus / as sysdba;
SQL> STARTUP UPGRADE
SQL> SPOOL patch.log
SQL> @?/rdbms/admin/catupgrd.sql

等跑完

SQL> SPOOL OFF

b. 关闭并重启数据库

SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP

c. 编译无效PL/SQL包



SQL> @?/rdbms/admin/utlrp.sql

d. 检查升级是否成功,如果所有组件的status都是valid表示升级成功。



SQL> SELECT COMP_NAME, VERSION, STATUS FROM SYS.DBA_REGISTRY;

e. 检查是否有升级错误



SQL> select * from utl_recomp_errors;

f. 修改系统兼容性参数

SQL> alter system set compatible='10.2.0.4.0' scope=spfile;

SQL> SHUTDOWN



SQL> STARTUP

升级完成。







建立資料庫 instance
先確認 listener.ora 跟 tnsnames.ora  不然 listener 不正確會一直出現 ORA-12514

ref :
http://alexlucy99.blogspot.tw/2015/02/ora-12514-tns.html
http://blog.itpub.net/18841027/viewspace-1059866/
http://stackoverflow.com/questions/10786782/ora-12514-tnslistener-does-not-currently-know-of-service-requested-in-connect-d

在 $ORACLE_HOME/network/admin/

處理 listener.ora

$ vim listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /oracle10/102)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = db3)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )

** 這樣是動態監聽 可以用
SQL> alter system register; 
進行手動註冊
靜態監聽則要把 SID 記在 listener.ora 裡

查詢 :
select value from v$parameter where name='service_names';
select instance_name from v_$instance;


處理 tnsnames.ora
$ vim tnsnames.ora

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

listener_hisspn =
 (ADDRESS = (PROTOCOL = TCP)(HOST = db3)(PORT = 1521))

hisspn =
(DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = db3)(PORT = 1521))
  (CONNECT_DATA =
    (SERVER = dedicated)
    (SERVICE_NAME = hisspn)
  )
)

然後用 dbca 建立新的 instance

ref : http://docs.oracle.com/cd/B16276_01/doc/server.102/b14196/install003.htm#BABJBDIF

$ export LANG=en_US
$ dbca



要自訂項目所以選 custom

這邊是設定 service name 跟 sid
依照需要設定 不一定要 host.domain


設定共同密碼 或是可以分開設
先單純用 FileSystem 

FlashRecovery 關掉
設定 archive log (這個可以在建起來之後再改)
這邊要依情況改 SGA
改 processes 

改 CHARSET 跟 NATIONAL CHARSET

這邊要改檔案位置到需要的地方




如果剛剛沒弄好 tnsnames.ora 跟 listener.ora 的話會出現這個