'dblink'에 해당되는 글 4건

  1. 2022.02.28 DATAPUMP,CTAS,DBLINK
  2. 2016.02.18 Truncate Table From a Remote Database
  3. 2009.11.20 DBLINK시 LOB CLOB 컬럼오류 해결
  4. 2007.12.07 DATABASE LINK 사용법
ORACLE/Migration2022. 2. 28. 00:23
반응형

오라클 데이터펌프

create directory pump_dir as '/backup/datapump';

grant read,write on directory pump_dir to hr;

expdp system/oracle dumpfile=scott.dmp directory=pump_dir schemas=scott

schema import
SYS@newdb> select tablespace_name, contents from dba_tablespaces;
Schema import 작업시 export 했을때의 정보들과 명칭이 다르면 remap 작업을 해줘야합니다. 
scott 계정을 import 하기위해서  default tablespace와 
default temporary tablespace의 명칭을 맞춰줘야하니 미리 확인해봤습니다. 
기본으로 사용할  tablespace도 만들어주겠습니다.

 

SYS@newdb> create tablespace dump datafile '/opt/oracle/app/oradata/newdb/dump01.dbf' size 200m;
스키마의 기본 테이블스페이스를 미리 만들어줬습니다. 이제 import 작업을 진행해보겠습니다.

impdp system/oracle dumpfile=scott.dmp directory=pump_dir remap_tablespace=users:dump

impdp system/oracle dumpfile=hr.dmp directory=pump_dir remap_schema=hr:scott remap_tablespace=examples:dump
database link 생성
create database link expdp_net01 connect to system \
identified by oracle using 'expdp_test'

db link 확인
*Local DB에 파일 남기기

expdp system/oracle network_link=expdp_net01 directory=dump_dir \
dumpfile=expdp_net01_%U.dmp logfile=expdp_net01.log \
job_name=net_01 

※ Long TYPE 등 NETWORK_LINK로 받아지지 않는 것이 있으므로 확인 필요

*Remote DB에 파일 남기기
expdp system/oracle@expdp_test directory=dump+dir \
dumpfile=expdp_net01_%U.dmp logfile=expdp+net01.log \
jog_name =remote_exp 

※DB Link와 Network_Link를 이용하면 Local DB쪽에 dmp 파일이 생성되며,Network Alias만 이용하면
Remote DB쪽에 dmp파일이 생성된다.

 

============================================================================

database link 생성
create database link expdp_net01 connect to system \
identified by oracle using 'expdp_test'

db link 확인
*Local DB에 파일 남기기

expdp system/oracle network_link=expdp_net01 directory=dump_dir \
dumpfile=expdp_net01_%U.dmp logfile=expdp_net01.log \
job_name=net_01 

※ Long TYPE 등 NETWORK_LINK로 받아지지 않는 것이 있으므로 확인 필요

*Remote DB에 파일 남기기
expdp system/oracle@expdp_test directory=dump+dir \
dumpfile=expdp_net01_%U.dmp logfile=expdp+net01.log \
jog_name =remote_exp 

※DB Link와 Network_Link를 이용하면 Local DB쪽에 dmp 파일이 생성되며,Network Alias만 이용하면
Remote DB쪽에 dmp파일이 생성된다.​


============================================================================CTAS 활용과 주의사항

테이블의 형식만 복사하기 위한 마이그레이션 작업에 사용된다.
기존 테이블의 데이터를 새로 생성하기 위해 테이블 재구성에 사용된다.
기존 테이블이 가지고있는 기본값, 제약조건, 인덱스 등은 복사할 수 없다.
파티션 테이블일 경우엔 일반 테이블로 복사된다.

select 'create table ' ||segment_name||' as select * from '||owner||'.'||segment_name||'@'||'link'||';' 
from dba_segments
where owner='SYS' and segment_type='TABLE PARTITION' and  rownum <11;

SQL> select distinct segment_type from dba_segments;

SEGMENT_TYPE
------------------
INDEX
CLUSTER
TABLE PARTITION
LOBINDEX
TABLE SUBPARTITION
SYSTEM STATISTICS
LOBSEGMENT
INDEX PARTITION
ROLLBACK
TABLE
LOB PARTITION
NESTED TABLE
TYPE2 UNDO

select 'insert into  ' ||segment_name||' as select * from '||owner||'.'||segment_name||'@'||'link'||';' 
from dba_segments
where owner='SYS' and segment_type='TABLE PARTITION' AND rownum <11;

select segment_TYPE,COUNT(*) FROM DBA_SEGMENTS GROUP BY SEGMENT_TYPE;


select 'create table ' ||table_name||' as select * from '||owner||'.'||table_name||'@'||'link'||';' 
from dba_tables
where owner='SYS' and rownum <11;

select 'insert into  ' ||segment_name||' as select * from '||owner||'.'||segment_name||'@'||'link'||';' 
from dba_segments
where owner='SYS' and segment_type='TABLE' AND rownum <11;

select owner,segment_name,PARTITION_NAME
from dba_segments
where owner='SYS' and segment_type='TABLE' and PARTITION_NAME <> ''

 select table_name from dict where table_name like '%PARTITION%';
 
select table_owner,table_name,PARTITION_NAME,PARTITION_POSITION from dba_tab_partitions order by 1,2,4;


select table_owner,table_name,count(*) from dba_tab_partitions group by table_owner,table_name;

SQL> CREATE PUBLIC DATABASE LINK 링크이름
CONNECT TO <연결하고자 하는 user>
IDENTIFIED BY <연결하고자 하는 user password>
USING '원격 db alias'

일반유저에게 Private DB LINK 생성권한 부여
SQL> grant create database link to 유저명;


Public 으로 생성 할 수 있는 권한 부여
SQL> grant create public database link to 유저명;


dba_db_links dictionary 에서 자세한 내용 조회 가능합니다

SQL> select * from dba_db_links;


사용법은 다음 과 같습니다.
select 컬럼명 from 테이블명@db_link명

connect scott/tiger;
select dbms_metadata.get_ddl('TABLE',u.table_name )
from user_tables u;
select dbms_metadata.get_ddl('INDEX',u.index_name)
from user_indexes u;

반응형
Posted by [PineTree]
ORACLE/ADMIN2016. 2. 18. 10:09
반응형

Truncate Table From a Remote Database


Truncating from a remote database is not allowed. On a development database environment, developers are in need of truncating certain tables on a regular basis. Delete is allowed over database link, that’s an option. But, that’s a bad example for allowing fragmentation and high water mark over the period of time.

If you try to truncate a table on a remote database, you will get the following error:
ORA-02021: DDL operations are not allowed on a remote database.

As, procedure can be executed over a dblink, so following workaround can be a good option on such scenario.

1.    Create a procedure on Remote Database that can truncate
CREATE OR REPLACE PROCEDURE
Trunc_Rem_Tab(p_table_name VARCHAR2) AS
   v_sql_error_code PLS_INTEGER;
   v_sql_error_message VARCHAR2(512);
BEGIN
   EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || p_table_name;
EXCEPTION
   WHEN OTHERS THEN
      v_sql_error_code := SQLCODE;
      v_sql_error_message := SQLERRM(v_sql_error_code);
      DBMS_OUTPUT.ENABLE(5000);
      DBMS_OUTPUT.PUT_LINE('OTHER ERROR');
      DBMS_OUTPUT.PUT_LINE(v_sql_error_message);
END Truncate_Remote_Table;

2.    Execute the procedure from local database.
BEGIN
   Trunc_Rem_Tab@REMOTE_LINK('TEST');
END;


반응형
Posted by [PineTree]
ORACLE/ADMIN2009. 11. 20. 13:50
반응형

-- DB링크를 만든다.

CREATE DATABASE LINK DB링크명
CONNECT TO scott IDENTIFIED BY tiger USING 'DB링크명';

 

-- 원격테이블의 컬럼에 clob 혹은 long과 같은 데이터 타입이 존재한다.
select * from 원격테이블@DB링크명
where rownum = 1
-- 에러가 발생한다.  ORA-22992:원격테이블로부터 선택된 LOB위치를 사용할 수 없습니다.


-- 따라서 로컬에 원격지의 테이블을 만들고 그대로 만들어 준다.
create table temp_원격테이블
as
select * from 원격테이블@DB링크명
where 1=2;

-- 그리고나서 원격지 테이블을 그대로 insert해온다.
insert into temp_원격테이블
select * from 원격테이블@DB링크명


-- 이제 로컬테이블로 되어 있다.
select * from temp_원격테이블
where rownum = 1;


반응형

'ORACLE > ADMIN' 카테고리의 다른 글

oracle 권한확인  (0) 2009.12.04
emca 재구성  (0) 2009.11.20
logminer + 불완전 복구  (0) 2009.11.19
Index Coalesce VS. Shrink  (0) 2009.11.06
REDO log buffer 캐쉬의 튜닝 및 REDO Latch 경합의 해결 방법  (0) 2009.11.06
Posted by [PineTree]
ORACLE/ADMIN2007. 12. 7. 00:16
반응형


DATABASE LINK 사용 방법
=======================


먼저 한글 data간의 전달을 위해 두 db간의 character set이 같아야 합니다.
character set을 확인하는 방법은

sqlplus system/manager
select * from v$nls_parameters;
하여 보면 nls_characterset에 대한 값이 나옵니다.

 
  예를 위해 다음과 같은 환경을 가정하겠습니다.
    
           HOST NAME    :      HP7     -       SUN7      
      
           ORACLE_SID   :      ORA7   -    ORATEST 
    
  이라 할 때

  1)  HP7 에서 SUN7로 DB LINK 생성하기. 

 

      scott/tiger 로 Login

    SQL*NET V1의 경우
      SQL> create public database link  HP7TOSUN6
                connect to scott identified by tiger
                using 't:SUN7:ORATEST';

    (rdbms 7.3 이상은 SQL*NET v2 를 사용하십시오)


    SQL*NET V2의 경우

 

create [public |private] DATABASE LINK {사용할 링크 명}
 CONNECT TO {접속 아이디} IDENTIFIED BY {접속암호}using'연결문자열';   

 

 public 일 경우 모든 사용자가 사용할 수 있으며 pribate일 경우에는 생성한 사용자만 사용할 수있다.
 
 링크 이름을 지정하는 데 숫자가 먼저 올 수 없다.


      SQL> create public database link HP7TOSUN7
           connect to scott identified by tiger
           using 'ORATEST';

      로 하면 된다.

      이 때 V2인 경우의 ORATEST는 $ORACLE_HOME/network/admin/ directory의
      tnsnames.ora file 내에 지정된 service name이다.
      tnsnames.ora의 service name이 잘 setting 되어 있는지 확인하는 방법
      : SQL*Plus scott/tiger@service name했을 때, SQL*Plus에 log-in되어야
      합니다.
    

  2> SUN7 에 있는 TABLE의 select 및 view(view는 필요에 따라 생성) 작성,
     HP에서 작업
   
      SQL> select * from emp@HP7TOSUN7;

      SQL> create view emp_view as select *
           from emp@HP7TOSUN7 a
           where a.deptno = 10;
                   
  3> HP7 에서 SYNONYM을 생성하여 사용하는 경우

 

         SQL> create synonym emp for emp@HP7TOSUN7;
         SQL> select * from emp;

 

   로 한다면 간단히 분산 DB의 환경에서 사용할 수 있습니다.

  select를 제외한 DML(insert, update, delete)을 하려면,
  sql*plus log-in 시에 다음과 같은 option이 display 되어야 합니다.

  SQL*Plus: Release 3.3.3.0.0 - Production on Mon Jan 19 14:18:47 1998
  Copyright (c) Oracle Corporation 1979, 1996.  All rights reserved.

  Connected to:
  Oracle7 Server Release 7.3.3.4.0 with the 64-bit option - Production
  Release With the distributed, ......
  ------------------------------------

  remote 작업의 예

  select * from table_name@HP7TOSUN7;
  insert into table_name@HP7TOSUN7;
  delete table_name@HP7TOSUN7;
  ...

  (단 SERVER TO SERVER로 NETWORK 환경이 구축되어 있어야 하고,
  listener 가 반드시 떠 있어야 합니다.)

 

DATABASE LINK 삭제하기

 
 DROP [public|private\ database link {삭제할링크 명};

 

==db links 조회

 

==USER ACCOUNT

SELECT * FROM USER_DB_LINKS

 

--DBA ACCOUNT

SELECT * FROM DBA_DB_LINKS

 

/* NEW 오라클 테이블 비우기 */
select 'truncate table '||table_name||';' from user_tables;


 

/* NEW 오라클 노로깅 */
select 'alter table '||table_name||' nologging;' from user_tables ;


 

/* NEW 오라클 index drop */
select 'drop index '||object_name||';' from user_objects
where object_type = 'INDEX';


 

/* NEW 오라클 인서트  */
select 'insert /*+ append */ into '||table_name||' select * from '||table_name||'@dblinkname;'
from user_tables
where owner = 'KVDBA';


 


/* NEW 오라클 테이블 로깅으로 변경 */
select 'alter table '||table_name||' logging;' from user_tables;


덧글. 오라클이 CBO이면 analyze 를 수행할것을 권장...

반응형

'ORACLE > ADMIN' 카테고리의 다른 글

오라클 캐릭터 셋 변경(CHARACTER SET)  (0) 2008.04.02
오라클 파라미터 관련 사이트 링크  (0) 2007.12.13
oracle lock  (0) 2007.08.14
ORACLE relink  (0) 2007.08.07
Oradebug Command  (0) 2007.08.04
Posted by [PineTree]