PDB Remote Clone in Oracle Database 19c之01-環(huán)境準(zhǔn)備

1.環(huán)境檢查(源庫(kù))

sql / as sysdba

SET SQLFORMAT ansiconsole

SQL> show pdbs;
  CON_ID CON_NAME   OPEN MODE    RESTRICTED   
       2 PDB$SEED   READ ONLY    NO           
       3 PDB2       READ WRITE   NO   

SELECT property_name, property_value
FROM   database_properties
WHERE  property_name = 'LOCAL_UNDO_ENABLED';
------------------------------------------------------
PROPERTY_NAME        PROPERTY_VALUE   
LOCAL_UNDO_ENABLED   TRUE  

SQL> SELECT log_mode FROM   v$database;
LOG_MODE     
ARCHIVELOG  

2.UNDO梳理
sql sys/123456@xag224:1521/pdb2 as sysdba
SET SQLFORMAT ansiconsole

select tablespace_name,file_name,bytes/1024/1024 mb from dba_temp_files 
union all 
select tablespace_name,file_name,bytes/1024/1024 mb from dba_data_files;
--------------------------------------------------------------------------
TABLESPACE_NAME   FILE_NAME                                   MB 
TEMP              /home/oradata/MPCDB/pdb2/temp01.dbf         36 
SYSTEM            /home/oradata/MPCDB/pdb2/system01.dbf      270 
SYSAUX            /home/oradata/MPCDB/pdb2/sysaux01.dbf      330 
UNDOTBS1          /home/oradata/MPCDB/pdb2/undotbs01.dbf     105 
USERS             /home/oradata/MPCDB/pdb2/users01.dbf         5 

#此處為測(cè)試環(huán)境故設(shè)置100M,生產(chǎn)環(huán)境要放大10G以上
ALTER DATABASE DATAFILE '/home/oradata/MPCDB/pdb2/undotbs01.dbf' RESIZE 200M;
ALTER DATABASE DATAFILE '/home/oradata/MPCDB/pdb2/undotbs01.dbf' AUTOEXTEND ON NEXT 50M;

3.TEMP 梳理

CREATE TEMPORARY TABLESPACE TS TEMPFILE
'/home/oradata/MPCDB/pdb2/TS_1.dbf' SIZE 64M REUSE AUTOEXTEND ON NEXT 128M  MAXSIZE 1G,
'/home/oradata/MPCDB/pdb2/TS_2.dbf' SIZE 64M REUSE AUTOEXTEND ON NEXT 128M  MAXSIZE 1G
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

ALTER TABLESPACE TS TABLESPACE GROUP TS_GP;

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TS_GP;
#如無(wú)法刪除則需重啟db
drop tablespace TEMP including contents and datafiles;
select * from dba_tablespace_groups;

4.整理用戶(hù)表空間

create tablespace US datafile 
'/home/oradata/MPCDB/pdb2/US_1.dbf' size 32M AUTOEXTEND ON NEXT 32M MAXSIZE UNLIMITED, 
'/home/oradata/MPCDB/pdb2/US_2.dbf' size 32M AUTOEXTEND ON NEXT 32M MAXSIZE UNLIMITED
 extent management local segment space management auto;

ALTER DATABASE DEFAULT TABLESPACE US;

drop tablespace USERS including contents and datafiles;
select tablespace_name,file_name,bytes/1024/1024 mb from dba_temp_files 
 union all 
select tablespace_name,file_name,bytes/1024/1024 mb from dba_data_files;
-------------------------------------------------------------------------
TABLESPACE_NAME   FILE_NAME                                   MB 
TS                /home/oradata/MPCDB/pdb2/TS_1.dbf           64 
TS                /home/oradata/MPCDB/pdb2/TS_2.dbf           64 
SYSTEM            /home/oradata/MPCDB/pdb2/system01.dbf      270 
SYSAUX            /home/oradata/MPCDB/pdb2/sysaux01.dbf      330 
UNDOTBS1          /home/oradata/MPCDB/pdb2/undotbs01.dbf     200 
US                /home/oradata/MPCDB/pdb2/US_1.dbf           32 
US                /home/oradata/MPCDB/pdb2/US_2.dbf           32 

5.創(chuàng)建新用戶(hù)

CREATE USER xag IDENTIFIED BY "123456" DEFAULT TABLESPACE US TEMPORARY TABLESPACE TS_GP;

GRANT DBA to xag;

#修改密碼(可選)
alter  user  xag identified  by "xag123";
#賬戶(hù)鎖定后解鎖命令(可選) sys or system
alter  user xag  account unlock;
#設(shè)置用戶(hù)密碼無(wú)限次嘗試登錄
alter profile default limit failed_login_attempts unlimited;
#設(shè)置用戶(hù)密碼不過(guò)期:
alter profile default limit password_life_time unlimited;
#查看配置的參數(shù)
select profile,RESOURCE_NAME,resource_type,limit from dba_profiles where 
RESOURCE_NAME in('FAILED_LOGIN_ATTEMPTS','PASSWORD_LIFE_TIME') and profile='DEFAULT';

創(chuàng)建測(cè)試自動(dòng)插入job(system用戶(hù)下)

begin
  dbms_network_acl_admin.create_acl
  (     
    acl        => 'utl_http.xml',          -- 文件名稱(chēng)
    description => 'HTTP Access',          -- 描述
    principal  => 'XAG',                -- 授權(quán)或者取消授權(quán)賬號(hào),大小寫(xiě)敏感
    is_grant    => TRUE,                   -- 授權(quán)還是取消授權(quán)
    privilege  => 'connect',               -- 授權(quán)或者取消授權(quán)的權(quán)限列表
    start_date  => null,                   -- 起始日期
    end_date    => null                    -- 結(jié)束日期
  );
end;
/

begin
  dbms_network_acl_admin.add_privilege (    -- 添加訪問(wèn)權(quán)限列表項(xiàng)
    acl        => 'utl_http.xml',          -- 剛才創(chuàng)建的acl名稱(chēng)
    principal  => 'XAG',                -- 授權(quán)或取消授權(quán)用戶(hù)
    is_grant  => TRUE,                    -- 與上同
    privilege  => 'resolve',                -- 權(quán)限列表
    start_date => null,                   
    end_date  => null
  );
end;
/

begin
  dbms_network_acl_admin.assign_acl(acl => 'utl_http.xml', host =>'*');
end;
/

創(chuàng)建測(cè)試job(xag下)

SQL> show user;
USER is "SYS"

SQL> conn xag/123456@xag224:1521/pdb2;

SQL> show user;
USER is "XAG"


create table my_healt_check
as
select utl_inaddr.get_host_address as host_address
,utl_inaddr.get_host_name as host_name
,sys_context('USERENV','CON_NAME') as db_name
,sysdate as create_time from dual;

create or replace procedure pr_my_healt_check_insert as
begin
  delete from my_healt_check a where a.create_time<sysdate-1/24;
  insert into my_healt_check(host_address,host_name,db_name,create_time)
  select utl_inaddr.get_host_address,utl_inaddr.get_host_name,sys_context('USERENV','CON_NAME'),sysdate from dual;
  commit;
end;
/

Declare job1 Number;
Begin
  dbms_job.submit(job1,'pr_my_healt_check_insert;',Sysdate,'sysdate + (1/(24*60))');
  Commit;
End;
/

or

declare
  v_count int := 0;
begin
  select count(*) into v_count from user_scheduler_jobs where job_name='TEST_JOB1';
  if v_count > 0 then
    dbms_scheduler.drop_job('HEALT_CHECK');
  end if;
  dbms_scheduler.create_job (
    job_name        => 'healt_check',
    job_type        => 'STORED_PROCEDURE',
    job_action      => 'pr_my_healt_check_insert',
    start_date      => sysdate,
    repeat_interval => 'FREQ=MINUTELY;INTERVAL=1',
    AUTO_DROP       =>  FALSE,
    enabled         => true
  );
end;
/

CREATE OR REPLACE VIEW V_XAG_JOB1 AS
SELECT job,to_char(LAST_DATE,'yyyy-mm-dd hh24:mi:ss') as last_date
,to_char(next_date,'yyyy-mm-dd hh24:mi:ss') as next_date,to_char(total_time,9999999999) as total_time
,to_char(case when failures is null then 0 else failures end,9999999999)  as failures
,broken,what,interval FROM user_jobs order by job;

CREATE OR REPLACE VIEW V_XAG_JOB2 AS
SELECT JOB_NAME,JOB_ACTION job,to_char(START_DATE,'yyyy-mm-dd hh24:mi:ss') as START_DATE
,REPEAT_INTERVAL,ENABLED,to_char(LAST_START_DATE,'yyyy-mm-dd hh24:mi:ss') as LAST_START_DATE
,to_char(NEXT_RUN_DATE,'yyyy-mm-dd hh24:mi:ss') as NEXT_RUN_DATE
,COMMENTS
FROM user_scheduler_jobs order by JOB_NAME;

select * from V_XAG_JOB1

select * from V_XAG_JOB2

select host_address ,host_name,db_name, to_char(create_time,'hh24:mi:ss')
from my_healt_check order by create_time desc;

DB啟動(dòng)時(shí) open all pdb (sys 下)

CREATE TRIGGER open_all_pdbs
AFTER STARTUP
ON DATABASE
BEGIN
  EXECUTE IMMEDIATE 'alter pluggable database all open';
END open_all_pdbs;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末盅称,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子糠爬,更是在濱河造成了極大的恐慌拙寡,老刑警劉巖庐橙,帶你破解...
    沈念sama閱讀 216,372評(píng)論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件鼻疮,死亡現(xiàn)場(chǎng)離奇詭異怯伊,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)陋守,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)水评,“玉大人,你說(shuō)我怎么就攤上這事中燥。” “怎么了疗涉?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,415評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)吟秩。 經(jīng)常有香客問(wèn)我咱扣,道長(zhǎng)涵防,這世上最難降的妖魔是什么闹伪? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,157評(píng)論 1 292
  • 正文 為了忘掉前任壮池,我火速辦了婚禮偏瓤,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘椰憋。我一直安慰自己厅克,他們只是感情好橙依,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,171評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布硕旗。 她就那樣靜靜地躺著褪储,像睡著了一般。 火紅的嫁衣襯著肌膚如雪鲤竹。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,125評(píng)論 1 297
  • 那天辛藻,我揣著相機(jī)與錄音,去河邊找鬼吱肌。 笑死,一個(gè)胖子當(dāng)著我的面吹牛纺蛆,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播桥氏,決...
    沈念sama閱讀 40,028評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼猛铅,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了奸忽?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,887評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤欠雌,失蹤者是張志新(化名)和其女友劉穎疙筹,沒(méi)想到半個(gè)月后桨昙,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體腌歉,經(jīng)...
    沈念sama閱讀 45,310評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,533評(píng)論 2 332
  • 正文 我和宋清朗相戀三年桂塞,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了馍驯。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片玛痊。...
    茶點(diǎn)故事閱讀 39,690評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡狂打,死狀恐怖擂煞,靈堂內(nèi)的尸體忽然破棺而出趴乡,到底是詐尸還是另有隱情,我是刑警寧澤晾捏,帶...
    沈念sama閱讀 35,411評(píng)論 5 343
  • 正文 年R本政府宣布惦辛,位于F島的核電站劳秋,受9級(jí)特大地震影響胖齐,放射性物質(zhì)發(fā)生泄漏玻淑。R本人自食惡果不足惜呀伙,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,004評(píng)論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望干像。 院中可真熱鬧驰弄,春花似錦、人聲如沸戚篙。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)浪耘。三九已至,卻和暖如春七冲,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背澜躺。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,812評(píng)論 1 268
  • 我被黑心中介騙來(lái)泰國(guó)打工抒蚜, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留耘戚,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,693評(píng)論 2 368
  • 正文 我出身青樓饿这,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親蛹稍。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,577評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容