Home Database Mysql Tutorial Oracle元数据重构实验

Oracle元数据重构实验

Jun 07, 2016 pm 02:54 PM
or database

在Oracle世界中,我们经常使用的性能工具AWR、作业Scheduler和RMAN工具,甚至Data Pump工具,都是建立在数据字典的基础上。

元数据是几乎所有数据库都具有的基础数据,其中包括基础数据字典、系统功能视图和函数结构等内容。越是功能强大成熟的数据库产品,其元数据信息越是众多复杂。在Oracle世界中,我们经常使用的性能工具AWR、作业Scheduler和RMAN工具,甚至Data Pump工具,都是建立在数据字典的基础上。

大部分数据字典是在sys和system用户schema下,普通用户只是通过同义词调用和访问对象,删除破坏的风险的是比较低的。在实践工作中,主要有两种情况会破坏元数据:管理员帐号误操作和系统内部运行数据损坏。无论是哪一种情况,元数据损坏的故障通常是很麻烦的,越是基础的元数据损坏,故障现象就越是紧急复杂和多变。

数据库组件之间,存在严格的依赖关系。一个基础元数据损坏,可能导致若干依赖的组件不能成功编译使用。如果是一些单纯的组件,如XDB、Data Pump的损坏,可以调用特定的创建脚本重建对象。但是如果是一些基础的组件错误,连带骨牌效应,就需要重建数据字典了。

重建数据字典是需要终止暂停数据库服务的,而且存在一定的风险,所以一定要慎重行事,选择适当的时间窗口进行操作。本篇主要介绍11gR2环境下如何进行元数据恢复。

1、环境说明

笔者使用Oracle 11gR2进行测试,版本编号为11.2.0.4。

[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Sun Sep 27 11:18:12 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

在进行回复之前,要继续完善的备份操作,确保一旦操作失败,起码可以恢复到操作之前的情况,不会让问题变得更糟。

备份手段很多,笔者使用冷备份手段。注意:如果我们可以实现shutdown immediate完全关闭,只需要关闭后备份数据文件、控制文件就可以了。

首先自动生成备份语句。

SQL> select 'cp '||name||' /backup' from v$controlfile;

'CP'||NAME||'/BACKUP'

--------------------------------------------------------------------------------

cp /u01/app/oradata/SICSDB/controlfile/o1_mf_b0m00wf1_.ctl /backup

cp /u01/app/fast_recovery_area/SICSDB/controlfile/o1_mf_b0m00wfq_.ctl /backup

SQL> select 'cp '||file_name||' /backup' from dba_data_files;

'CP'||FILE_NAME||'/BACKUP'

--------------------------------------------------------------------------------

cp /u01/app/oradata/SICSDB/datafile/o1_mf_users_b0lzzg2m_.dbf /backup

(篇幅原因,有省略……)

cp /u01/app/oradata/SICSDB/datafile/o1_mf_uattestt_byr5560d_.dbf /backup

16 rows selected

关闭数据库,最好是完全关闭。

[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Sun Sep 27 11:08:58 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

SQL> conn / as sysdba

Connected.

SQL> shutdown immediate;   

Database closed.

Database dismounted.

ORACLE instance shut down.

在操作系统层面执行语句。

[oracle@localhost ~]$ cp /u01/app/oradata/SICSDB/datafile/o1_mf_users_b0lzzg2m_.dbf /backup

(篇幅原因,有省略……)

[oracle@localhost ~]$ cd /backup/

[oracle@localhost backup]$ ls -l

total 33586456

-rw-r-----. 1 oracle oinstall    9748480 Sep 27 11:09 o1_mf_b0m00wf1_.ctl

-rw-r-----. 1 oracle oinstall    9748480 Sep 27 11:10 o1_mf_b0m00wfq_.ctl

(篇幅原因,有省略……)

-rw-r-----. 1 oracle oinstall  406331392 Sep 27 11:10 o1_mf_users_b0lzzg2m_.dbf

完成了备份,就可以开始进行修复。

2、修复元数据

首先启动数据库,进入upgrade模式。

[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Sun Sep 27 11:18:12 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup upgrade

ORACLE instance started.

Total System Global Area 5344731136 bytes

Fixed Size                  2262656 bytes

Variable Size            1207961984 bytes

Database Buffers        4127195136 bytes

Redo Buffers                7311360 bytes

Database mounted.

Database opened.

系列执行脚本一共有三个,分别进行不同的数据创建。执行脚本一定要在Server端进行,确保版本的一致性。首先执行catalog.sql脚本。

SQL> spool test.log

SQL> @?/rdbms/admin/catalog.sql

Grant succeeded.

PL/SQL procedure successfully completed.

TIMESTAMP

--------------------------------------------------------------------------------

COMP_TIMESTAMP CATALOG    2015-09-27 11:20:34

第二步执行catproc.sql脚本。

SQL> @?/rdbms/admin/catproc.sql

PL/SQL procedure successfully completed.

SQL> 

SQL> SELECT dbms_registry_sys.time_stamp('CATPROC') AS timestamp FROM DUAL;

TIMESTAMP

--------------------------------------------------------------------------------

COMP_TIMESTAMP CATPROC    2015-09-27 11:29:12

1 row selected.

最后,重新编译compile所有的对象。

SQL> SET SERVEROUTPUT OFF

SQL> @?/rdbms/admin/utlrp.sql

DOC>

DOC>  1. Query showing jobs created by UTL_RECOMP

DOC>        SELECT job_name FROM dba_scheduler_jobs

DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';

DOC>

DOC>  2. Query showing UTL_RECOMP jobs that are running

DOC>        SELECT job_name FROM dba_scheduler_running_jobs

DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';

DOC>#

SQL> 

SQL> DECLARE

2    threads pls_integer := &&1;

3  BEGIN

4    utl_recomp.recomp_parallel(threads);

5  END;

6  /

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Analysis of the basic principles of MySQL database management system Analysis of the basic principles of MySQL database management system Mar 25, 2024 pm 12:42 PM

Analysis of the basic principles of the MySQL database management system MySQL is a commonly used relational database management system that uses structured query language (SQL) for data storage and management. This article will introduce the basic principles of the MySQL database management system, including database creation, data table design, data addition, deletion, modification, and other operations, and provide specific code examples. 1. Database Creation In MySQL, you first need to create a database instance to store data. The following code can create a file named "my

Tips and practices for handling Chinese garbled characters in databases with PHP Tips and practices for handling Chinese garbled characters in databases with PHP Mar 27, 2024 pm 05:21 PM

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

See all articles