经常听到删库跑路,刚刚好读《Oracle Database Administrator s Guide 11g Release 2 (11.2) 》有个drop database,搞一波。
SQL> drop database;
drop database
*
ERROR at line 1:
ORA-01586: database must be mounted EXCLUSIVE and not open for this operation
#不能直接删除,需要将数据库开启到mount EXCLUSIVE状态先关闭数据库:
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
#启动到mount状态:
SQL> startup mount;
ORACLE instance started.
Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 478154296 bytes
Database Buffers 301989888 bytes
Redo Buffers 2596864 bytes
Database mounted.
#将数据库设置为EXCLUSIVE状态:
SQL> alter system enable restricted session;
System altered.
#确认数据库状态
SQL> select status,logins from v$instance;
STATUS LOGINS
---------------- ----------------------
MOUNTED RESTRICTED
#drop数据库
SQL> drop database;
Database dropped.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
#看alter.log可以看到drop日志进行了删除操作
drop database
Deleted file /oradata/orcl/system01.dbf
Deleted file /oradata/orcl/sysaux01.dbf
Deleted file /oradata/orcl/undotbs01.dbf
Deleted file /oradata/orcl/users01.dbf
Deleted file /oradata/orcl/example01.dbf
Deleted file /oradata/orcl/redo01.log
Deleted file /oradata/orcl/redo02.log
Deleted file /oradata/orcl/redo03.log
Deleted file /oradata/orcl/temp01.dbf
Deleted file /u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f
Shutting down archive processes
Archiving is disabled
启动数据库到 MOUNTED RESTRICTED状态后方可执行,删除了控制文件、数据文件以及其他记录在控制文件的文件
不会删除归档文件以及备份文件