需求:預設無法直接刪除Oracle的users表空間,直接嘗試刪除會有報錯如下:
SQL> drop tablespace users including contents and datafiles;
drop tablespace users including contents and datafiles
*
ERROR at line 1:
ORA-12919: Can not drop the default permanent tablespace
報錯很明確,USERS目前作為資料庫目前預設的永久表空間,暫不支援直接刪除。
進一步查詢,看到有很多使用者的確是預設用到了USERS表空間:
SQL>
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
SYSRAC USERS 04-JAN-23
SYSTEM SYSTEM 04-JAN-23
SYSBACKUP USERS 04-JAN-23
AUDSYS USERS 04-JAN-23
SYSKM USERS 04-JAN-23
SYS SYSTEM 04-JAN-23
SYSDG USERS 04-JAN-23
OUTLN SYSTEM 04-JAN-23
GSMADMIN_INTERNAL SYSAUX 04-JAN-23
GSMUSER USERS 04-JAN-23
DIP USERS 04-JAN-23
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
XS$NULL SYSTEM 04-JAN-23
REMOTE_SCHEDULER_AGENT USERS 04-JAN-23
DBSFWUSER SYSAUX 04-JAN-23
ORACLE_OCM USERS 04-JAN-23
SYS$UMF USERS 04-JAN-23
DBSNMP SYSAUX 04-JAN-23
APPQOSSYS SYSAUX 04-JAN-23
GSMCATUSER USERS 04-JAN-23
GGSYS SYSAUX 04-JAN-23
XDB SYSAUX 04-JAN-23
ANONYMOUS SYSAUX 04-JAN-23
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
WMSYS SYSAUX 04-JAN-23
OJVMSYS USERS 04-JAN-23
CTXSYS SYSAUX 04-JAN-23
MDSYS SYSAUX 04-JAN-23
ORDSYS USERS 04-JAN-23
ORDDATA USERS 04-JAN-23
ORDPLUGINS USERS 04-JAN-23
SI_INFORMTN_SCHEMA USERS 04-JAN-23
OLAPSYS SYSAUX 04-JAN-23
MDDATA USERS 04-JAN-23
APEX_180200 SYSAUX 04-JAN-23
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
FLOWS_FILES SYSAUX 04-JAN-23
APEX_PUBLIC_USER USERS 04-JAN-23
APEX_INSTANCE_ADMIN_USER USERS 04-JAN-23
PDBADMIN USERS 04-JAN-23
HR SYSAUX 04-JAN-23
JINGYU USERS 06-JAN-23
TEAM USERS 01-MAR-23
40 rows selected.
但現在XTTS測試,客戶現有源端的users表空間也需要遷移(有使用者資料,注意我們並不推薦在users存放使用者資料)
如果真想刪除,也是可以的,就是修改預設表空間,但還需要考慮USERS裡面是否有資料要遷移,比較麻煩。
現場實施的兄弟提出能否重新命名users表空間,這是個好主意,實測是OK,操作也很簡單,一條語句搞定:
SQL> alter tablespace users rename to user1;
Tablespace altered.
瞬間執行完成,然後再查使用者的預設表空間,也已經從users已經變成user1:
SQL> select USERNAME, DEFAULT_TABLESPACE, CREATED from dba_users order by 3;
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
SYSRAC USER1 04-JAN-23
SYSTEM SYSTEM 04-JAN-23
SYSBACKUP USER1 04-JAN-23
AUDSYS USER1 04-JAN-23
SYSKM USER1 04-JAN-23
SYS SYSTEM 04-JAN-23
SYSDG USER1 04-JAN-23
OUTLN SYSTEM 04-JAN-23
GSMADMIN_INTERNAL SYSAUX 04-JAN-23
GSMUSER USER1 04-JAN-23
DIP USER1 04-JAN-23
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
XS$NULL SYSTEM 04-JAN-23
REMOTE_SCHEDULER_AGENT USER1 04-JAN-23
DBSFWUSER SYSAUX 04-JAN-23
ORACLE_OCM USER1 04-JAN-23
SYS$UMF USER1 04-JAN-23
DBSNMP SYSAUX 04-JAN-23
APPQOSSYS SYSAUX 04-JAN-23
GSMCATUSER USER1 04-JAN-23
GGSYS SYSAUX 04-JAN-23
XDB SYSAUX 04-JAN-23
ANONYMOUS SYSAUX 04-JAN-23
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
WMSYS SYSAUX 04-JAN-23
OJVMSYS USER1 04-JAN-23
CTXSYS SYSAUX 04-JAN-23
MDSYS SYSAUX 04-JAN-23
ORDSYS USER1 04-JAN-23
ORDDATA USER1 04-JAN-23
ORDPLUGINS USER1 04-JAN-23
SI_INFORMTN_SCHEMA USER1 04-JAN-23
OLAPSYS SYSAUX 04-JAN-23
MDDATA USER1 04-JAN-23
APEX_180200 SYSAUX 04-JAN-23
USERNAME DEFAULT_TABLESPACE CREATED
------------------------------ ------------------------------ ---------
FLOWS_FILES SYSAUX 04-JAN-23
APEX_PUBLIC_USER USER1 04-JAN-23
APEX_INSTANCE_ADMIN_USER USER1 04-JAN-23
PDBADMIN USER1 04-JAN-23
HR SYSAUX 04-JAN-23
JINGYU USER1 06-JAN-23
TEAM USER1 01-MAR-23
40 rows selected.
查詢資料庫預設永久表空間也都變成了USER1:
SQL> SELECT PROPERTY_VALUE
FROM DATABASE_PROPERTIES
WHERE PROPERTY_NAME = 'DEFAULT_PERMANENT_TABLESPACE'; 2 3
PROPERTY_VALUE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
USER1