ORA-01145错误是Oracle数据库中的一个常见错误,它表示在没有启用介质恢复的情况下尝试立即脱机,这个错误通常是由于在关闭数据库之前,没有正确地完成数据泵导出(expdp)或者闪回技术(flashback)操作所导致的,为了解决这个问题,您需要确保在关闭数据库之前正确地完成了这些操作,并且启用了介质恢复功能。
数据泵导出(expdp)
数据泵导出(expdp)是Oracle提供的一个用于将数据库中的数据和元数据导出到本地文件系统的工具,在使用数据泵导出之前,您需要创建一个目录对象(directory object),用于存储导出的数据文件,您可以使用数据泵导出命令将数据从数据库导出到该目录对象中。
以下是一个简单的示例,演示如何使用数据泵导出命令将数据从Oracle数据库导出到本地文件系统:
1、创建目录对象:
CREATE DIRECTORY exp_dir AS '/path/to/export/directory';
2、授予DBA权限:
GRANT READ, WRITE ON DIRECTORY exp_dir TO dba;
3、使用数据泵导出命令:
expdp username/password@db_name SCHEMAS=schema_name DIRECTORY=exp_dir DUMPFILE=data.dmp LOGFILE=expdp.log
闪回技术(Flashback)
闪回技术(Flashback)是Oracle提供的一种用于恢复到某一特定时间点的功能,当您需要恢复到某个错误的状态时,可以使用闪回技术,在使用闪回技术之前,您需要先创建一个闪回表(Flashback Table),用于存储闪回的对象,您可以使用闪回技术命令将数据库恢复到指定的时间点。
以下是一个简单的示例,演示如何使用闪回技术命令将数据库恢复到某一特定时间点:
1、创建闪回表:
CREATE TABLE flashback_table AS SELECT * FROM original_table WHERE 1=0;
2、使用闪回技术命令:
FLASHBACK TABLE original_table TO TIMESTAMP('2022-01-01 00:00:00');
启用介质恢复功能
在关闭数据库之前,您需要确保已经启用了介质恢复功能,介质恢复功能允许您在数据库崩溃后从备份介质中恢复数据库,要启用介质恢复功能,请按照以下步骤操作:
1、登录到Oracle数据库服务器上的sys用户。
2、设置环境变量:
export ORACLE_BASE=/path/to/oracle/base export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1 export PATH=$ORACLE_HOME/bin:$PATH
3、编辑参数文件(init.ora或spfile):
[database] log_archive_dest_1='LOCATION=(local) DISK=backup_disk GROUP=db_group SIZE=50M' log_archive_dest_2='LOCATION=(local) DISK=backup_disk GROUP=db_group SIZE=50M' log_archive_dest_state_1=ARCHIVED;RECOVERY_FILE_DEST=LOCATION=(local) DISK=backup_disk GROUP=db_group SIZE=50M;RECOVERY_FILE_DEST_STATE=ENABLED;FLASHBACK_TO_TIMESTAMP=TO_TIMESTAMP('2022-01-01 00:00:00') RESTORE_ONLY=YES FLASHBACK_FILENAME='flashback.bkp' FLASHBACK_TABLESPACES='USER' FLASHBACK_DATAFILES='DATAFILE' FLASHBACK_INDEXES='INDEX' FLASHBACK_LOCKS='LOCK' FLASHBACK_BINARY_LOGS='BINARY' FLASHBACK_REDO_LOGS='REDO' FLASHBACK_SNAPSHOTS='SNAPSHOT' FLASHBACK_CONTROLFILE='CONTROLFILE' FLASHBACK_DATABASE='DATABASE' FLASHBACK_TABLESPACE='TABLESPACE' FLASHBACK_DATAFILE='DATAFILE' FLASHBACK_INDEX='INDEX' FLASHBACK_LOCK='LOCK' FLASHBACK_BINLOG='BINLOG' FLASHBACK_UNDO='UNDO' FLASHBACK_SAVEPOINT='SAVEPOINT';ARCHIVELOG ALL;RESETLOGS;ALTER SYSTEM SET db_block_replication = TRUE SCOPE=SPFILE;ALTER SYSTEM SET dblink="";ALTER SYSTEM SET controlfiles="";ALTER SYSTEM SET logfile="";ALTER SYSTEM SET maxinstances=1 SCOPE=SPFILE;ALTER SYSTEM SET processes=0 SCOPE=SPFILE;ALTER SYSTEM SET tempspacesize=0 SCOPE=SPFILE;ALTER SYSTEM SET temporaryspacesize=0 SCOPE=SPFILE;ALTER SYSTEM SET transactionnestlevel=6 SCOPE=SPFILE;ALTER SYSTEM SET dataguardchecksum=FALSE SCOPE=SPFILE;ALTER SYSTEM SET dbmgrctlexpr="" SCOPE=SPFILE;ALTER SYSTEM SET dbmgrcontrolfile="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqrsh="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsc="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsi="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqso="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsf="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsr="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsj="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsp="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsn="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsv="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsb="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsa="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqse="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsz="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsx="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsu="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsg="" SCOPE=SPFILE;ALTER SYSTEM SET dbmrgrmtqsh="" SCOPE=SPFILE;ALTER SYSTEM SET dbmgrctrlexpr="" SCOPE=SPFILE;ALTER SYSTEM SET dbmgrcontrolfile="" SCOPE=SPFILE;ALTER SYSTEM SET dbmgrcontrolfilesize="" SCOPE=SPFILE;ALTER SYSTEM SET dbmgrcontrolfiletype="" SCOPE=SPFILE;ALTER DATABASE QUALIFIED BY sys/admin@orcl ADD PRIMARY KEY (id);CREATE TABLESPACE users INCLUDING ALL TABLES IN SCHEMA public STORAGE (INITIAL 64K NEXT 1M MAXSIZE UNLIMITED);CREATE TABLESPACE groups INCLUDING ALL TABLES IN SCHEMA public STORAGE (INITIAL 64K NEXT 1M MAXSIZE UNLIMITED);CREATE TABLESPACE temp INCLUDING ALL TABLES IN SCHEMA public STORAGE (INITIAL 64K NEXT 1M MAXSIZE UNLIMITED);CREATE TABLESPACE users2 INCLUDING ALL TABLES IN SCHEMA users STORAGE (INITIAL 64K NEXT 1M MAXSIZE UNLIMITED);CREATE TABLESPACE groups2 INCLUDING ALL TABLES IN SCHEMA groups STORAGE (INITIAL 64K NEXT 1M MAXSIZE UNLIMITED);CREATE PROCEDURE sptestproc() NOSQL SQL NULL EXTERNAL SQLNAME 'sptestproc' NOT DETERMINISTIC NOSIDEEFFECTS CONTAINS SQLBEGINDECLARE a INT := NULL;SELECT COUNT(*) INTO a FROM testtable WHERE id = aENDDECLARE a INT := NULL;SELECT COUNT(*) INTO a FROM testtable WHERE id = aENDEXECUTE IMMEDIATE 'DROP PROCEDURE sptestproc';COMMIT WORK
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/186231.html