tetsoukyl的Blog
2024年4月16日 星期二
使用ChatGPT來學習oracle 特定主題
2020年12月24日 星期四
對物件的影響程度 Repair Chained Rows (蟾蜍) < Alter Table Move < Rebuild Table (蟾蜍)
對物件的影響程度
Rebuild Table (蟾蜍) > Alter Table Move (reorg) > Repair Chained Rows (蟾蜍)
1. Rebuild Table (蟾蜍) : Create Indexes, Compile Dependencies, Analyze Table
2. Alter Table Move (reorg): Rebuild Indexes, Analyze Table
3. Repair Chained Rows (蟾蜍): Analyze Table
SQL> create table tbl_1224 as select * from employees;
Table created.
SQL> desc tbl_1224;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPLOYEE_ID NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
SQL> CREATE INDEX idx_tbl_1224_01 ON tbl_1224
(EMPLOYEE_ID); 2
Index created.
SQL> select EMAIL from tbl_1224;
-------------------------
DOCONNEL
DGRANT
JWHALEN
MHARTSTE
PFAY
SMAVRIS
HBAER
SHIGGINS
WGIETZ
SKING
NKOCHHAR
SQL> CREATE OR REPLACE FORCE VIEW vw_1224
AS
select EMAIL from tbl_1224; 2 3
View created.
SQL> select * from vw_1224;
-------------------------
DOCONNEL
DGRANT
JWHALEN
MHARTSTE
PFAY
SMAVRIS
HBAER
SHIGGINS
WGIETZ
SKING
NKOCHHAR
SQL> select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and object_type ='VIEW'; 2 3
OWNER
------------------------------
OBJECT_NAME
--------------------------------------------------------------------------------
OBJECT_TYPE STATUS
------------------- -------
HR1
VW_1224
VIEW VALID
SQL> select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and status <> 'VALID';
2 3
no rows selected
--Alter Table Move 不會讓 depenedncies 的狀態成為 INVALID
SQL> alter table tbl_1224 move;
Table altered.
SQL> select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and status <> 'VALID'; 2 3
no rows selected
SQL> select
a.owner OWNER,
a.INDEX_NAME NAME,
a.TABLE_NAME TABLE_NAME,
a.STATUS STATUS
from all_indexes a
where A.OWNER = 'HR1'
and A.STATUS <> 'VALID'; 2 3 4 5 6 7 8
OWNER NAME
------------------------------ ------------------------------
TABLE_NAME STATUS
------------------------------ --------
HR1 IDX_TBL_1224_01
TBL_1224 UNUSABLE
SQL> select * from vw_1224;
-------------------------
DOCONNEL
DGRANT
JWHALEN
MHARTSTE
PFAY
SMAVRIS
HBAER
SHIGGINS
WGIETZ
SKING
NKOCHHAR
SQL> ALTER INDEX IDX_TBL_1224_01 REBUILD;
Index altered.
-- TOAD Rebuild Table 會讓 depenedncies 的狀態成為 INVALID
SQL> SET LINESIZE 200
SQL> ALTER TABLE HR1.TBL_1224 RENAME TO TBL_1224_X;
Table altered.
SQL> CREATE TABLE HR1.TBL_1224
(
EMPLOYEE_ID NUMBER(6),
FIRST_NAME VARCHAR2(20 BYTE),
LAST_NAME VARCHAR2(25 BYTE) NOT NULL,
EMAIL VARCHAR2(25 BYTE) NOT NULL,
PHONE_NUMBER VARCHAR2(20 BYTE),
HIRE_DATE DATE NOT NULL,
JOB_ID VARCHAR2(10 BYTE) NOT NULL,
SALARY NUMBER(8,2),
COMMISSION_PCT NUMBER(2,2),
MANAGER_ID NUMBER(6),
DEPARTMENT_ID NUMBER(4)
) 2 3 4 5 6 7 8 9 10 11 12 13 14
15 ;
Table created.
SQL> INSERT /*+ APPEND */
2 INTO HR1.TBL_1224 INS_TBL
(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL,
PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY,
3 4 5 COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
SELECT
EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL,
PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY,
COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID
FROM HR1.TBL_1224_X SEL_TBL;
6 7 8 9 10 COMMIT;
214 rows created.
SQL>
Commit complete.
SQL>
SQL>
SQL>
SQL> DROP INDEX HR1.IDX_TBL_1224_01;
Index dropped.
SQL> CREATE INDEX HR1.IDX_TBL_1224_01 ON HR1.TBL_1224
(EMPLOYEE_ID) 2 ;
Index created.
SQL> select
a.owner OWNER,
a.INDEX_NAME NAME,
a.TABLE_NAME TABLE_NAME,
a.STATUS STATUS
from all_indexes a
where A.OWNER = 'HR1'
and A.STATUS <> 'VALID'; 2 3 4 5 6 7 8
no rows selected
SQL> select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and status <> 'VALID'; 2 3
OWNER OBJECT_NAME OBJECT_TYPE STATUS
------------------------------ -------------------------------------------------------------------------------------------------------------------------------- ------------------- -------
HR1 VW_1224 VIEW INVALID
SQL> select * from vw_1224;
-------------------------
DOCONNEL
DGRANT
JWHALEN
MHARTSTE
PFAY
SMAVRIS
HBAER
SHIGGINS
WGIETZ
SKING
NKOCHHAR
-- 使用到 VIEW VW_1224 之後,則DB會自動COMPILE該物件
SQL> select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and status <> 'VALID'; 2 3
no rows selected
-- 這是手動COMPILE該物件
SQL> ALTER VIEW "HR1"."VW_1224" COMPILE;
View altered.
SQL> select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and status <> 'VALID'; 2 3
no rows selected
SQL> select
a.owner OWNER,
a.INDEX_NAME NAME,
a.TABLE_NAME TABLE_NAME,
a.STATUS STATUS
from all_indexes a
where A.OWNER = 'HR1'
and A.STATUS <> 'VALID'; 2 3 4 5 6 7 8
no rows selected
SQL>
Oracle database link and view status
結論:
1. view 裡面有使用到 database link
2. create view 之後,drop database link,view testdb88_hr1_usertables 還是顯示為 VALID
3. 但是 select from testdb88_hr1_usertables 顯示錯誤 ORA-04063: view "HR1.TESTDB88_HR1_USERTABLES" has errors
4. 重新compile TESTDB88_HR1_USERTABLES COMPILE 時,報錯 Warning: compiled but with compilation errors
5. 這時 view status 顯示為 INVALID
CREATE DATABASE LINK HR1_TESTDB88
CONNECT TO HR1
IDENTIFIED BY "password"
USING 'testdb88_DB11G';
CREATE OR REPLACE FORCE VIEW HR1.TESTDB88_HR1_USERTABLES
AS
SELECT *
FROM user_tables@HR1_TESTDB88;
select * from HR1.TESTDB88_HR1_USERTABLES
select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and object_type ='VIEW';
DROP DATABASE LINK HR1_TESTDB88;
select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and object_type ='VIEW';
select * from HR1.TESTDB88_HR1_USERTABLES;
ORA-04063: view "HR1.TESTDB88_HR1_USERTABLES" has errors
SELECT *
FROM user_tables@HR1_TESTDB88;
Error at line 2
ORA-02019: connection description for remote database not found
ALTER VIEW TESTDB88_HR1_USERTABLES COMPILE;
Warning: compiled but with compilation errors
select OWNER, object_name, OBJECT_TYPE , status
from dba_objects
where owner = 'HR1' and object_type ='VIEW';
OWNER OBJECT_NAME OBJECT_TYPE STATUS
-------- ------------ ------------ -------
HR1 TESTDB88_HR1_USERTABLES VIEW INVALID
1 row selected.
2020年12月23日 星期三
何時重建索引 When to Rebuild Indexes
http://www.dba-oracle.com/t_oracle_analyze_index.htm
Oracle ANALYZE INDEX
Oracle Database Tips by Donald Burleson
http://www.remote-dba.net/t_tuning_index_rebuilding.htm
Index Rebuilding Techniques
Oracle Tips by Burleson Consulting
何時重建索引
如果每次訪問獲取的塊過多,則我們可能要重建索引,因為過多的塊獲取表示碎片化的B樹結構。另一個重建條件是刪除的葉子節點佔索引節點的20%以上的情況。重建的另一個原因是當任何索引顯示的深度為4或更大時。
When to Rebuild Indexes
Rebuild an Oracle index with the following command:
ALTER INDEX index_name REBUILD TABLESPACE tablespace_name;
We might want to rebuild an index if the block gets per access is excessive, since excessive block gets indicate a fragmented B-tree structure. Another rebuild condition would be cases where deleted leaf nodes comprise more than 20 percent of the index nodes. Another reason to rebuild is when any index shows a depth of 4 or greater.
使用alter index rebuild進行索引重建是非常安全的命令。如果出現任何問題,Oracle會中止該操作並將現有索引保留在原處。
Index rebuilding with the alter index rebuild is a very safe command. If anything goes wrong, Oracle aborts the operation and leaves the existing index in place.
2020年11月30日 星期一
Oracle expdp impdp CONTENT=METADATA_ONLY testing
新增兩個USER,創建表,賦與權限。實驗看看哪個復原方式可以達到我要的效果。
CREATE USER HR3
IDENTIFIED BY VALUES 'S:78DE8200DFBDE7C8A683934A5AF43E2FE8614C357C0BBA8DBC7C7898D824;9F1BFB4526C62B14'
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
-- 3 Roles for HR3
GRANT CONNECT TO HR3;
GRANT RESOURCE TO HR3;
GRANT SELECT_CATALOG_ROLE TO HR3;
ALTER USER HR3 DEFAULT ROLE ALL;
-- 5 System Privileges for HR3
GRANT ALTER SYSTEM TO HR3;
GRANT CREATE DATABASE LINK TO HR3;
GRANT CREATE MATERIALIZED VIEW TO HR3;
GRANT ON COMMIT REFRESH TO HR3;
GRANT UNLIMITED TABLESPACE TO HR3;
CREATE USER HR4
IDENTIFIED BY VALUES 'S:78DE8200DFBDE7C8A683934A5AF43E2FE8614C357C0BBA8DBC7C7898D824;9F1BFB4526C62B14'
DEFAULT TABLESPACE TEST_TBS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
-- 3 Roles for HR4
GRANT CONNECT TO HR4;
GRANT RESOURCE TO HR4;
GRANT SELECT_CATALOG_ROLE TO HR4;
ALTER USER HR4 DEFAULT ROLE ALL;
-- 5 System Privileges for HR4
GRANT ALTER SYSTEM TO HR4;
GRANT CREATE DATABASE LINK TO HR4;
GRANT CREATE MATERIALIZED VIEW TO HR4;
GRANT ON COMMIT REFRESH TO HR4;
GRANT UNLIMITED TABLESPACE TO HR4;
SQL> create table hr3.EMPLOYEES_TEST as select * from HR1.EMPLOYEES_TEST;
Table created.
SQL> grant select on hr3.EMPLOYEES_TEST to hr4;
Grant succeeded.
[oracle@testdb89 dpdump]$ expdp DIRECTORY=DATA_PUMP_DIR SCHEMAS=HR3 CONTENT=METADATA_ONLY EXCLUDE=statistics dumpfile=hr3_20201130.dmp
Export: Release 11.2.0.4.0 - Production on Mon Nov 30 12:42:39 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** DIRECTORY=DATA_PUMP_DIR SCHEMAS=HR3 CONTENT=METADATA_ONLY EXCLUDE=statistics dumpfile=hr3_20201130.dmp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
>>> DBMS_AW_EXP: SYS.AW$EXPRESS: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWMD: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE10G: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWXML: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWREPORT: OLAP not enabled
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
>>> DBMS_AW_EXP: SYS.AW$EXPRESS: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWMD: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE10G: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWXML: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWREPORT: OLAP not enabled
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/u01/app/oracle/admin/DB11G/dpdump/hr3_20201130.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Nov 30 12:42:55 2020 elapsed 0 00:00:10
[oracle@testdb89 dpdump]$ expdp DIRECTORY=DATA_PUMP_DIR SCHEMAS=HR4 CONTENT=METADATA_ONLY EXCLUDE=statistics dumpfile=hr4_20201130.dmp
Export: Release 11.2.0.4.0 - Production on Mon Nov 30 12:44:47 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** DIRECTORY=DATA_PUMP_DIR SCHEMAS=HR4 CONTENT=METADATA_ONLY EXCLUDE=statistics dumpfile=hr4_20201130.dmp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
>>> DBMS_AW_EXP: SYS.AW$EXPRESS: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWMD: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE10G: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWXML: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWREPORT: OLAP not enabled
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/u01/app/oracle/admin/DB11G/dpdump/hr4_20201130.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Nov 30 12:45:02 2020 elapsed 0 00:00:07
[oracle@testdb89 dpdump]$ expdp DIRECTORY=DATA_PUMP_DIR SCHEMAS=HR3,HR4 CONTENT=METADATA_ONLY EXCLUDE=statistics dumpfile=hr34_20201130.dmp
Export: Release 11.2.0.4.0 - Production on Mon Nov 30 12:45:17 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** DIRECTORY=DATA_PUMP_DIR SCHEMAS=HR3,HR4 CONTENT=METADATA_ONLY EXCLUDE=statistics dumpfile=hr34_20201130.dmp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
>>> DBMS_AW_EXP: SYS.AW$EXPRESS: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWMD: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE10G: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWXML: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWREPORT: OLAP not enabled
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
>>> DBMS_AW_EXP: SYS.AW$EXPRESS: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWMD: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWCREATE10G: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWXML: OLAP not enabled
>>> DBMS_AW_EXP: SYS.AW$AWREPORT: OLAP not enabled
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/u01/app/oracle/admin/DB11G/dpdump/hr34_20201130.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Nov 30 12:45:30 2020 elapsed 0 00:00:07
[oracle@testdb89 dpdump]$ expdp include=user SCHEMAS=HR4 DIRECTORY=DATA_PUMP_DIR dumpfile=userhr4_20201130.dmp
Export: Release 11.2.0.4.0 - Production on Mon Nov 30 13:36:29 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** include=user SCHEMAS=HR4 DIRECTORY=DATA_PUMP_DIR dumpfile=userhr4_20201130.dmp
Estimate in progress using BLOCKS method...
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/USER
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/u01/app/oracle/admin/DB11G/dpdump/userhr4_20201130.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Nov 30 13:36:41 2020 elapsed 0 00:00:04
SQL> DROP USER HR4 CASCADE;
[oracle@testdb89 dpdump]$ impdp DIRECTORY=DATA_PUMP_DIR DUMPFILE=userhr4_20201130.dmp
Import: Release 11.2.0.4.0 - Production on Mon Nov 30 13:37:24 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** DIRECTORY=DATA_PUMP_DIR DUMPFILE=userhr4_20201130.dmp
Processing object type SCHEMA_EXPORT/USER
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Mon Nov 30 13:38:40 2020 elapsed 0 00:00:02
用expdp include=user 的export file 做impdp,只會create user。沒有相關system, object, role 等權限。
沒有權限,連登入資料庫都會失敗。
[oracle@testdb89 dpdump]$ sqlplus hr4/hr
SQL*Plus: Release 11.2.0.4.0 Production on Mon Nov 30 13:41:44 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-01045: user HR4 lacks CREATE SESSION privilege; logon denied
Enter user-name:
[oracle@testdb89 dpdump]$ sqlplus / as sysdba
SQL> DROP USER HR4 CASCADE;
[oracle@testdb89 dpdump]$ impdp DIRECTORY=DATA_PUMP_DIR DUMPFILE=hr4_20201130.dmp
缺 -- 1 Object Privilege for HR4
GRANT SELECT ON HR3.EMPLOYEES_TEST TO HR4;
[oracle@testdb89 dpdump]$ sqlplus / as sysdba
SQL> DROP USER HR4 CASCADE;
[oracle@testdb89 dpdump]$ impdp DIRECTORY=DATA_PUMP_DIR DUMPFILE=hr34_20201130.dmp
Import: Release 11.2.0.4.0 - Production on Mon Nov 30 12:47:47 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** DIRECTORY=DATA_PUMP_DIR DUMPFILE=hr34_20201130.dmp
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"HR3" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "HR3"."EMPLOYEES_TEST" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 2 error(s) at Mon Nov 30 12:47:56 2020 elapsed 0 00:00:02
缺 -- 1 Object Privilege for HR4
GRANT SELECT ON HR3.EMPLOYEES_TEST TO HR4;
因為 ORA-39151: Table "HR3"."EMPLOYEES_TEST" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
[oracle@testdb89 dpdump]$ sqlplus / as sysdba
SQL> DROP USER HR3 CASCADE;
SQL> DROP USER HR4 CASCADE;
[oracle@testdb89 dpdump]$ impdp DIRECTORY=DATA_PUMP_DIR DUMPFILE=hr34_20201130.dmp
Import: Release 11.2.0.4.0 - Production on Mon Nov 30 12:49:58 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** DIRECTORY=DATA_PUMP_DIR DUMPFILE=hr34_20201130.dmp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Mon Nov 30 12:50:09 2020 elapsed 0 00:00:02
將HR3, HR4 都完整drop,才會恢復的完整。 HR4 有 GRANT SELECT ON HR3.EMPLOYEES_TEST TO HR4;
SQL> set long 64000
SQL> select dbms_metadata.get_ddl('USER','HR3') from dual;
SQL> select dbms_metadata.get_ddl('USER','HR4') from dual;
DBMS_METADATA.GET_DDL('USER','HR4')
--------------------------------------------------------------------------------
CREATE USER "HR4" IDENTIFIED BY VALUES 'S:78DE8200DFBDE7C8A683934A5AF43E2FE86
14C357C0BBA8DBC7C7898D824;9F1BFB4526C62B14'
DEFAULT TABLESPACE "TEST_TBS"
TEMPORARY TABLESPACE "TEMP"
如果是想在開發機,設定和正式機相同的密碼。
ALTER USER "HR4" IDENTIFIED BY VALUES 'S:78DE8200DFBDE7C8A683934A5AF43E2FE86
14C357C0BBA8DBC7C7898D824;9F1BFB4526C62B14'
2020年11月24日 星期二
Oracle Row Chaining and Migration 圖示
The Secrets of Oracle Row Chaining and Migration
https://www.akadia.com/services/ora_chained_rows.html
Row Migration
We will migrate a row when an update to that row would cause it to not fit on the block anymore (with all of the other data that exists there currently). A migration means that the entire row will move and we just leave behind the «forwarding address». So, the original block just has the rowid of the new block and the entire row is moved.
Row Chaining
A row is too large to fit into a single database block. For example, if you use a 4KB blocksize for your database, and you need to insert a row of 8KB into it, Oracle will use 3 blocks and store the row in pieces. Some conditions that will cause row chaining are: Tables whose rowsize exceeds the blocksize. Tables with LONG and LONG RAW columns are prone to having chained rows. Tables with more then 255 columns will have chained rows as Oracle break wide tables up into pieces. So, instead of just having a forwarding address on one block and the data on another we have data on two or more blocks.
"alter table move tablespace" tips |
http://www.dba-oracle.com/t_alter_table_move_index_constraint.htm
reorg
Identifying Oracle Tables with Migrated/Chained Rowshttp://www.dba-oracle.com/t_identify_chained_rows.htm |
2020年10月30日 星期五
Oracle 11g Default Schemas
以下內容節錄自
http://www.oracle-wiki.net/premium:startdocsdefaultschemas
Oracle 11g Default Schemas
DEFAULT SCHEMA
USER NAME DEFAULT TABLESPACE TEMPORARY TABLESPACE LOCKED? DBA?
ANONYMOUS SYSAUX TEMP YES
APEX_030200 SYSAUX TEMP YES
APEX_PUBLIC_USER USERS TEMP YES
APPQOSSYS SYSAUX TEMP YES
BI USERS TEMP YES
CTXSYS SYSAUX TEMP YES
DBSNMP SYSTEM TEMP
DIP USERS TEMP YES
EXFSYS SYSAUX TEMP YES
FLOWS_FILES SYSAUX TEMP YES
HR USERS TEMP YES
IX USERS TEMP YES
MDDATA USERS TEMP YES
MDSYS SYSAUX TEMP YES
MGMT_VIEW SYSTEM TEMP
OE USERS TEMP YES
OLAPSYS SYSAUX TEMP YES
ORACLE_OCM USERS TEMP YES
ORDDATA SYSAUX TEMP YES
ORDPLUGINS SYSAUX TEMP YES
ORDSYS SYSAUX TEMP YES
OUTLN SYSTEM TEMP YES
OWBSYS SYSAUX TEMP YES
OWBSYS_AUDIT SYSAUX TEMP YES
PM USERS TEMP YES
SCOTT USERS TEMP YES
SH USERS TEMP YES
SI_INFORMTN_SCHEMA SYSAUX TEMP YES
SPATIAL_CSW_ADMIN_USR USERS TEMP YES
SPATIAL_WFS_ADMIN_USR USERS TEMP YES
SYS SYSTEM TEMP YES
SYSMAN SYSAUX TEMP
SYSTEM SYSTEM TEMP YES
WMSYS SYSAUX TEMP YES
XDB SYSAUX TEMP YES
XS$NULL USERS TEMP YES
SCHEMA OVERVIEW
ANONYMOUS
Purpose:Account that allows HTTP access to Oracle XML DB. It is used in place of the APEX_PUBLIC_USER account when the Embedded PL/SQL Gateway (EPG) is installed in the database. EPG is a Web server that can be used with Oracle Database. It provides the necessary infrastructure to create dynamic applications. See also XDB.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/catqm.sql
APEX_030200
Purpose:Part of the Oracle Application Express Suite - (Oracle APEX, previously named Oracle HTML DB) which is a freeware software development environment. It allows a fast development cycle to be achieved to create web based applications. The account owns the Application Express schema and metadata. See also APEX_PUBLIC_USER and FLOW_FILES.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/apex/apexins.sql
APEX_PUBLIC_USER
Purpose:Part of the Oracle Application Express Suite - (Oracle APEX, previously named Oracle HTML DB) which is a freeware software development environment. It allows a fast development cycle to be achieved to create web based applications. This minimally privileged account is used for Application Express configuration with Oracle HTTP Server and mod_plsql. See also APEX_030200 and FLOW_FILES.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/apex/apexins.sql
APPQOSSYS
Purpose:Used for storing/managing all data and metadata required by Oracle Quality of Service Management.
Safe To Remove:Yes
Recreation Script:$ORACLE_ADMIN/rdbms/admin/catqos.sql
BI
Purpose:The account that owns the Business Intelligence schema included in the Oracle Sample Schemas. See also HR, OE, SH, IX and PM.
Safe To Remove:Yes – run $ORACLE_HOME/demo/schema/drop_sch.sql
Recreation Script:$ORACLE_HOME/demo/schema/bus_intelligence/bi_main.sql
CTXSYS
Purpose:The account used to administer Oracle Text. Oracle Text enables the building of text query applications and document classification applications. It provides indexing, word and theme searching, and viewing capabilities for text.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ctx/admin/ctxsys.sql
DBSNMP
Purpose:The account used by the Management Agent component of Oracle Enterprise Manager to monitor and manage the database. Password is created at installation or database creation time.
Safe To Remove:Yes – run $ORACLE_HOME/rdbms/admin/catnsnmp.sql
Recreation Script:$ORACLE_HOME/rdbms/admin/catsnmp.sql
DIP
Purpose:The account used by the Directory Integration Platform (DIP) to synchronize the changes in Oracle Internet Directory with the applications in the database.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/catdip.sql
EXFSYS
Purpose:The account used internally to access the EXFSYS schema, which is associated with the Rules Manager and Expression Filter feature. This feature enables the building of complex PL/SQL rules and expressions. The EXFSYS schema contains the Rules Manager and Expression Filter DDL, DML, and associated metadata.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/exfsys.sql
FLOW_FILES
Purpose:Part of the Oracle Application Express Suite - (Oracle APEX, previously named Oracle HTML DB) which is a freeware software development environment. It allows a fast development cycle to be achieved to create web based applications. This account owns the Application Express uploaded files. See also APEX_030200 and APEX_PUBLIC_USER.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/apex/apexins.sql
HR
Purpose:The account that owns the Human Resources schema included in the Oracle Sample Schemas. See also BI, OE, SH, IX and PM.
Safe To Remove:Yes – run $ORACLE_HOME/demo/schema/drop_sch.sql
Recreation Script:$ORACLE_HOME/demo/schema/human_resources/hr_main.sql
IX
Purpose:The account that owns the Information Transport schema included in the Oracle Sample Schemas. See also BI, HR, OE, SH and PM.
Safe To Remove:Yes – run $ORACLE_HOME/demo/schema/drop_sch.sql
Recreation Script:$ORACLE_HOME/demo/schema/info_exchange/ix_main.sql
MDDATA
Purpose:The schema used by Oracle Spatial for storing Geocoder and router data. See also SPATIAL_CSW_ADMIN_USR , SPATIAL_WFS_ADMIN_USR and MDSYS.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/md/admin/catmd.sql
MDSYS
Purpose:The Oracle Spatial and Oracle Multimedia Locator administrator account. See also SPATIAL_CSW_ADMIN_USR , MDDATA and SPATIAL_WFS_ADMIN_USR.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ord/admin/ordinst.sql
MGMT_VIEW
Purpose:An account used by Oracle Enterprise Manager Database Control. Password is randomly generated at installation or database creation time. Users do not need to know this password.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/sysman/admin/emdrep/bin/RepManager
OE
Purpose:The account that owns the Order Entry schema included in the Oracle Sample Schemas. See also BI, HR, SH, IX and PM.
Safe To Remove:Yes – run $ORACLE_HOME/demo/schema/drop_sch.sql
Recreation Script:$ORACLE_HOME/ demo/schema/order_entry/oe_main.sql
OLAPSYS
Purpose:The account that owns the OLAP Catalog (CWMLite). This account has been deprecated, but is retained for backward compatibility.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/olap/admin/amdsys.sql
ORACLE_OCM
Purpose:This account contains the instrumentation for configuration collection used by the Oracle Configuration Manager.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/catocm.sql
ORDDATA
Purpose:This account contains the Oracle Multimedia DICOM data model.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ord/admin/ordisysc.sql
ORDPLUGINS
Purpose:The Oracle Multimedia user. Plug-ins supplied by Oracle and third-party, format plug-ins are installed in this schema. Oracle Multimedia enables Oracle Database to store, manage, and retrieve images, audio, video, DICOM format medical images and other objects, or other heterogeneous media data integrated with other enterprise information. See also ORDSYS and SI_INFORMTN_SCHEMA.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ord/admin/ordinst.sql
ORDSYS
Purpose:The Oracle Multimedia administrator account. See also ORDPLUGINS and SI_INFORMTN_SCHEMA.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ord/admin/ordinst.sql
OUTLN
Purpose:The account that supports plan stability. Plan stability prevents certain database environment changes from affecting the performance characteristics of applications by preserving execution plans in stored outlines. OUTLN acts as a role to centrally manage metadata associated with stored outlines.
Safe To Remove:No
Recreation Script:$ORACLE_HOME/rdbms/admin/sql.bsq. Recover from backup or recreate the database.
OWBSYS
Purpose:The account for administrating the Oracle Warehouse Builder repository. Access this account during the installation process to define the base language of the repository and to define Warehouse Builder workspaces and users. A data warehouse is a relational or multidimensional database that is designed for query and analysis. See also OWBSYS_AUDIT.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/owb/UnifiedRepos/cat_owb.sql
OWBSYS_AUDIT
Purpose:This account is used by the Warehouse Builder Control Center Agent to access the heterogeneous execution audit tables in the OWBSYS schema.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/owb/UnifiedRepos/cat_owb.sql
PM
Purpose:The account that owns the Product Media schema included in the Oracle Sample Schemas. See also BI, HR, OE, SH and IX.
Safe To Remove:Yes – run $ORACLE_HOME/demo/schema/drop_sch.sql
Recreation Script:$ORACLE_HOME/demo/schema/product_media/pm_main.sql
SCOTT
Purpose:An account used by Oracle sample programs and examples.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/utlsampl.sql
SH
Purpose:The account that owns the Sales History schema included in the Oracle Sample Schemas and is only available for Enterprise Edition installations. See also BI, HR, OE, IX and PM.
Safe To Remove:Yes – run $ORACLE_HOME/demo/schema/drop_sch.sql
Recreation Script:$ORACLE_HOME/demo/schema/sales_history/sh_main.sql
SI_INFORMTN_SCHEMA
Purpose:The account that stores the information views for the SQL/MM Still Image Standard. See also ORDPLUGINS and ORDSYS.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ord/admin/ordinst.sql
SPATIAL_CSW_ADMIN_USR
Purpose:The Catalog Services for the Web (CSW) account. It is used by the Oracle Spatial CSW cache manager to load all record type metadata, and record instances from the database into the main memory for the record types that are cached. See also SPATIAL_WFS_ADMIN_USR, MDDATA and MDSYS.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/md/admin/sdocswpv.sql
SPATIAL_WFS_ADMIN_USR
Purpose:The Web Feature Service (WFS) account. It is used by the Oracle Spatial WFS cache manager to load all feature type metadata, and feature instances from the database into main memory for the feature types that are cached. See also SPATIAL_CSW_ADMIN_USR , MDDATA and MDSYS.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/md/admin/sdowfspv.sql
SYS
Purpose:An account used to perform database administration tasks. Password is created at installation or database creation time.
Safe To Remove:No
Recreation Script:$ORACLE_HOME/rdbms/admin/sql.bsq. Recover from backup or recreate the database.
SYSMAN
Purpose:The account used to perform Oracle Enterprise Manager database administration tasks. The SYS and SYSTEM accounts can also perform these tasks. Password is created at installation or database creation time.
Safe To Remove:Yes
Recreation Script:Created as part of the dbconsole or Enterprise Manager build.
SYSTEM
Purpose:A default generic database administrator account for Oracle databases. For production systems, Oracle recommends creating individual database administrator accounts and not using the generic SYSTEM account for database administration operations. Password is created at installation or database creation time.
Safe To Remove:No
Recreation Script:$ORACLE_HOME/rdbms/admin/sql.bsq. Recover from backup or recreate the database.
WMSYS
Purpose:The account used to store the metadata information for Oracle Workspace Manager.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/owmctab.plb
XDB
Purpose:The account used for storing Oracle XML DB data and metadata. See also ANONYMOUS.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/catqm.sql
XS$NULL
Purpose:An internal account that represents the absence of a user in a session. Because XS$NULL is not a user, this account can only be accessed by the Oracle Database instance. XS$NULL has no privileges and no one can authenticate as XS$NULL, nor can authentication credentials ever be assigned to XS$NULL.
Safe To Remove:No
Recreation Script:$ORACLE_HOME/rdbms/admin/sql.bsq. Recover from backup or recreate the database.
OTHER ADMINISTRATIVE SCHEMA
The schema listed below are not installed by default, but can be built using the creation script(s) cited and any necessary additional steps as prescribed by the appropriate Oracle manual.
LBACSYS
Purpose:The account used to administer Oracle Label Security (OLS). It is created only when the Label Security custom option is installed.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/rdbms/admin/catlbacs.sql
WK_TEST
Purpose:The instance administrator for the default instance, WK_INST. After unlocking this account and assigning this user a password, then the cached schema password must also be updated using the administration tool Edit Instance Page. Ultra Search provides uniform search-and-location capabilities over multiple repositories, such as Oracle databases, other ODBC compliant databases, IMAP mail servers, HTML documents managed by a Web server, files on disk, and more. See also WKSYS
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ultrasearch/admin/wk0csys.sql
WKSYS
Purpose:An Ultra Search database super-user. WKSYS can grant super-user privileges to other users, such as WK_TEST. All Oracle Ultra Search database objects are installed in the WKSYS schema. See also WK_TEST
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ultrasearch/admin/wk0csys.sql
WKPROXY
Purpose:An administrative account of Application Server Ultra Search.
Safe To Remove:Yes
Recreation Script:$ORACLE_HOME/ultrasearch/admin/wk0csys.sql