You are on page 1of 16

IT Auxiliary

Oracle Database Operation Guide

Issue 01

Date 2013-06-30

HUAWEI TECHNOLOGIES CO., LTD.


Copyright © Huawei Technologies Co., Ltd. 2013. All rights reserved.
No part of this document may be reproduced or transmitted in any form or by any means without prior
written consent of Huawei Technologies Co., Ltd.

Trademarks and Permissions


and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.

All other trademarks and trade names mentioned in this document are the property of their respective
holders.

Notice
The purchased products, services and features are stipulated by the contract made between Huawei and
the customer. All or part of the products, services and features described in this document may not be
within the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,
information, and recommendations in this document are provided "AS IS" without warranties, guarantees
or representations of any kind, either express or implied.
The information in this document is subject to change without notice. Every effort has been made in the
preparation of this document to ensure accuracy of the contents, but all statements, information, and
recommendations in this document do not constitute a warranty of any kind, express or implied.

Huawei Technologies Co., Ltd.


Address: Huawei Industrial Base
Bantian, Longgang
Shenzhen 518129
People's Republic of China

Website: http://www.huawei.com

Email: support@huawei.com

Huawei Proprietary and Confidential


Issue 01 (2013-06-30) Copyright © Huawei i
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide About This Document

About This Document

Intended Audience
This document describes common operations on the Oracle database.
This document is intended for:
 Customer maintenance engineers
 Huawei maintenance engineers

Change History
Changes between document issues are cumulative. The latest document issue contains all the
changes made in earlier issues.

Issue 01 (2013-06-30)
This issue is the first official release.

Issue 01 (2013-06-30) Huawei Proprietary and Confidential ii


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Contents

Contents

About This Document....................................................................................................................ii


1 Common Operations.....................................................................................................................1
1.1 Checking Database Status..................................................................................................................................2
1.2 Checking the Database Version.........................................................................................................................3
1.3 Deleting Archive Logs.......................................................................................................................................3
1.4 Restarting a Database Instance in HA Networking Mode.................................................................................4
1.5 Restarting a Database Instance in RAC Networking Mode...............................................................................5
1.6 Recreating Indexes Online.................................................................................................................................6
1.7 Modifying the processes Parameter...................................................................................................................7
1.8 Modifying the shared_pool_size Parameter.......................................................................................................8
1.9 Modifying the log_buffer Parameter.................................................................................................................9
1.10 Expanding Tablespaces..................................................................................................................................10
1.11 Collecting Data Table Statistics and Index Statistics That Have Not Been Analyzed...................................11

Issue 01 (2013-06-30) Huawei Proprietary and Confidential iii


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Tables

Tables

Table 1-1 Path to the init.crs file.............................................................................................................................5

Issue 01 (2013-06-30) Huawei Proprietary and Confidential iv


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

1 Common Operations

About This Chapter


1.1 Checking Database Status
Check Oracle database status based on which you can perform maintenance and operations in
the database.
1.2 Checking the Database Version
Check the database version.
1.3 Deleting Archive Logs
Regularly delete archive logs. Otherwise, archive logs fill up the archive log directory, which
may cause database exceptions.
1.4 Restarting a Database Instance in HA Networking Mode
Only one database instance exists when the database is in HA networking mode. Restarting
the database instance affects service data. Therefore, restart the database instance only when
the database cannot be properly switched over.
1.5 Restarting a Database Instance in RAC Networking Mode
Each RAC node runs a database instance when the database is in RAC networking mode.
Restarting the database instance on a RAC node affects service data. Therefore, restart the
database instance on a RAC node only when the database cannot be properly switched over.
1.6 Recreating Indexes Online
If you recreate indexes online, indexes are recreated based on original indexes. Recreating
indexes online affects services. Therefore, stop services before recreating indexes online.
1.7 Modifying the processes Parameter
If processes is inappropriately set, services cannot gain access to the database.
1.8 Modifying the shared_pool_size Parameter
If shared_pool_size is inappropriately set, database performance is affected.
1.9 Modifying the log_buffer Parameter

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 1


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

If the value of log_buffer is less than the minimum value, wait events occur in the Redo
Buffers.
1.10 Expanding Tablespaces
Expand tablespaces so that new data can be written into tablespaces when the number of
database files continuously increases.
1.11 Collecting Data Table Statistics and Index Statistics That Have Not Been Analyzed
Collect data table statistics and index statistics that have not been analyzed to ensure that SQL
statement execution plans are correct.

1.1 Checking Database Status


Check Oracle database status based on which you can perform maintenance and operations in
the database.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus '/ as sysdba'
Step 3 Check database instance status.
SQL> select status, logins from v$instance;
STATUS LOGINS
------------------------ --------------------
OPEN ALLOWED

 The options of STATUS are as follows:


− OPEN: The database instance enters the OPEN state after the startup or alter
database open command is executed.
− STARTED: The database instance enters the STARTED state after the startup
nomount command is executed.
− MOUNTED: The database instance enters the MOUNTED state after the startup
mount or alter database close command is executed.
 The options of LOGINS are as follows:
− ALLOWED: indicates that all users can log in to the database.
− RESTRICTED: indicates that only database administrators (DBAs) can log in to the
database.
Step 4 Check database status.
SQL> select open_mode from v$database;
OPEN_MODE
----------------------------------------
READ WRITE

 If the value of OPEN_MODE is MOUNTED, the database is installed and allows only
creating control files and restoring the database.

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 2


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

 If the value of OPEN_MODE is READ WRITE, the database is started in read/write


mode and allows various operations.
 If the value of OPEN_MODE is READ ONLY, the database is started in read-only
mode to prevent dirty data. The database is started in read-only mode only during
maintenance.
----End

1.2 Checking the Database Version


Check the database version.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus '/ as sysdba'
Step 3 Check the database version.
SQL> select * from v$version;
The following information is displayed:
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production

The command output indicates that the database version is 11.1.0.7.0.

Alternatively, you can run the select * from registry$history; command to check the database version.
In the output of this command, the value in the VERSION column indicates the database version and
the value in the COMMENTS column indicates the database patch version.

----End

1.3 Deleting Archive Logs


Regularly delete archive logs. Otherwise, archive logs fill up the archive log directory, which
may cause database exceptions.

Precautions
Back up archive logs before deleting them.

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 3


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Log in to the RMAN.
rman target / nocatalog
Step 3 Delete archive logs.
RMAN> delete archivelog all;

The database is configured in the DataGuard or STREAMS environment. If the STREAMS environment
requires archive logs or the STREAM environment cannot be restored after longtime attempts, run the
following command:
RMAN> delete FORCE archivelog all;

Step 4 Log out of the RMAN.


RMAN> exit
----End

1.4 Restarting a Database Instance in HA Networking


Mode
Only one database instance exists when the database is in HA networking mode. Restarting
the database instance affects service data. Therefore, restart the database instance only when
the database cannot be properly switched over.

Precautions
If you forcibly stop the database instance, starting the database instance may fail, affecting
services. Therefore, obtain customer approval before forcibly stopping the database instance.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus '/ as sysdba'
Step 3 Stop the database instance.
 To immediately stop the database instance and roll back pending transactions, run the
following command:
SQL> shutdown immediate;
 If the database instance cannot be stopped a long time after you run the preceding
command, set up a connection to the database and run the following command to
forcibly stop the database instance:
SQL> shutdown abort;
Step 4 Start the database instance.

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 4


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

SQL> conn / as sysdba;


SQL> startup;
----End

1.5 Restarting a Database Instance in RAC Networking


Mode
Each RAC node runs a database instance when the database is in RAC networking mode.
Restarting the database instance on a RAC node affects service data. Therefore, restart the
database instance on a RAC node only when the database cannot be properly switched over.

Context
When the database is in RAC networking mode, three daemons init.cssd, init.crsd, and
init.evmd run in the database. When you restart a database instance, all resources except the
three daemons are stopped and then started.
The path to the init.crs file for restarting database instances varies depending on operating
systems. Table 1-1 describes the init.crs file path.

Table 1.1 Path to the init.crs file


Operating System File Path

SuSE Linux /etc/init.d/init.crs


HP-UX /sbin/init.d/init.crs
AIX /etc/init.crs
Solaris /etc/init.d/init.crs

Precautions
This operation applies only to the Oracle database 11g Release 1.

Procedure
Step 1 Log in to the operating system as the root user.
Step 2 Stop the database instance.
Determine the init.crs file path based on the operating system and run the following
command in the file path:
init.crs stop
For example, if the operating system is SuSE Linux, run the following command in
/etc/init.d/init.crs:
/etc/init.d/init.crs stop

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 5


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

Step 3 Start the database instance.


Determine the init.crs file path based on the operating system and run the following
command in the file path:
init.crs start
For example, if the operating system is SuSE Linux, run the following command in
/etc/init.d/init.crs:
/etc/init.d/init.crs start
startup will be queued to init within 30 seconds.

Step 4 Switch to the oracle user.


su - oracle
Step 5 Check the status of all resources in the database.
crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....SM1.asm application ONLINE ONLINE linux1102
ora....02.lsnr application ONLINE ONLINE linux1102
ora....102.gsd application ONLINE ONLINE linux1102
ora....102.ons application ONLINE ONLINE linux1102
ora....102.vip application ONLINE ONLINE linux1102

All resources must be in the ONLINE state.


----End

1.6 Recreating Indexes Online


If you recreate indexes online, indexes are recreated based on original indexes. Recreating
indexes online affects services. Therefore, stop services before recreating indexes online.

Precautions
If service user indexes expire, recreate the indexes.
Contact Huawei engineers for confirmation because recreating indexes online affects services
and apply for a sufficient maintenance time segment.
The duration for recreating indexes varies depending on the data volume in the database.
Before recreating indexes, evaluate the duration with the service side and developers.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus / as sysdba
Step 3 Query invalid indexes or index partitions.

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 6


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

SQL> select owner,index_name,status from dba_indexes where status='UNUSABLE'


and partitioned='NO' and owner='***';
SQL> select index_owner,index_name,partition_name,status from dba_ind_partitions
where status='UNUSABLE' and index_owner='***';
SQL> select index_owner,index_name,subpartition_name,status from
dba_ind_subpartitions where status='UNUSABLE' and index_owner='***';
In the preceding commands, *** indicates the alarm ID corresponding to an index.
Step 4 Recreate indexes.
SQL> alter index <owner.index_name> rebuild [online];
Index altered.

SQL> alter index <owner.index_name> rebuild partition <index_partition_name>


[online];
Index altered.

SQL> alter index <owner.index_name> rebuild subpartition <index_subpartition_name>


[online];
Index altered.

In the preceding commands, [online] indicates that indexes are recreated online.

If the command output is Index altered, indexes are recreated.


----End

1.7 Modifying the processes Parameter


If processes is inappropriately set, services cannot gain access to the database.

Precautions
After modifying processes, you must restart the database instance for the modification to take
effect, which affects services. Therefore, obtain approval from the customer, the service side,
and developers before modifying processes.
Determine the value of processes based on the site requirements.

Procedure
Step 1 Log in to the operating system as the root user.
Step 2 Obtain the IDs of oracle user processes.
ps -ef | grep LOCAL=NO
oracle 1323 1 0 17:03 ? 00:00:00 oraclemytest (LOCAL=NO)
oracle 1503 1350 0 17:03 pts/2 00:00:00 grep LOCAL=NO

Step 3 Stop the oracle user processes.

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 7


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

kill -9 Process ID
Step 4 Switch to the oracle user.
su - oracle
Step 5 Connect to the database.
sqlplus '/ as sysdba'
Step 6 Obtain the value of processes.
SQL> show parameter processes;
NAME TYPE VALUE
-------------------------- ----------- --------------
processes integer 800

Step 7 Change the value of processes.


For example, to change the value of processes to 1000, run the following command:
SQL> alter system set processes=1000 scope=spfile;
Step 8 Stop the database instance.
SQL> shutdown immediate;
Step 9 Start the database instance.
SQL> startup;
----End

1.8 Modifying the shared_pool_size Parameter


If shared_pool_size is inappropriately set, database performance is affected.

Context
The shared_pool_size parameter determines the row cache hit ratio that must be greater than
95%. If the row cache hit ratio is less than or equal to 95%, modify shared_pool_size to
increase the ratio. Determine the value of shared_pool_size based on the site requirements.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus '/ as sysdba'
Step 3 Check the row cache hit ratio.
SQL> select (1 - (SUM(getmisses)/SUM(gets)))*100 FROM v$rowcache;
(1-(SUM(GETMISSES)/SUM(GETS)))*100
----------------------------------
98.900438

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 8


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

Step 4 If the row cache hit ratio is less than or equal to 95%, check the shared pool size.
SQL> select bytes/1024/1024 from v$sgainfo where name='Shared Pool Size';
BYTES/1024/1024
---------------
480

Step 5 Change the value of shared_pool_size.


For example, to change the value of shared_pool_size to 800 (in MB), run the following
command:
SQL> alter system set shared_pool_size=800M scope=both;
----End

1.9 Modifying the log_buffer Parameter


If the value of log_buffer is less than the minimum value, wait events occur in the Redo
Buffers.

Precautions
After modifying log_buffer, you must restart the database instance for the modification to
take effect, which affects services. Therefore, obtain approval from the customer, the service
side, and developers before modifying log_buffer.
Determine the value of log_buffer based on the site requirements.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus '/ as sysdba'
Step 3 Check the size of the Redo Buffers.
SQL> select bytes/1024/1024 from v$sgainfo where name='Redo Buffers';
BYTES/1024/1024
---------------
15.7929688

Step 4 If the size of the Redo Buffers is less than the minimum value required by the site, change the
value of log_buffer.
For example, to change the value of log_buffer to 83886080 (in bytes), run the following
command:
SQL> alter system set log_buffer=83886080 scope=spfile;
Step 5 Stop the database instance.
SQL> shutdown immediate;

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 9


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

Step 6 Start the database instance.


SQL> startup;
----End

1.10 Expanding Tablespaces


Expand tablespaces so that new data can be written into tablespaces when the number of
database files continuously increases.

Precautions
Determine the size by which a tablespace is to be expanded based on the site requirements.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus '/ as sysdba'
Step 3 Check the vacancy rates of tablespaces.
SQL> SELECT D.TABLESPACE_NAME,SPACE "SUM_SPACE(M)",BLOCKS
SUM_BLOCKS,SPACE - NVL(FREE_SPACE, 0) "USED_SPACE(M)",(100-
ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 2))
"FREE_RATE(%)",FREE_SPACE "FREE_SPACE(M)"FROM (SELECT
TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024), 2)
SPACE,SUM(BLOCKS) BLOCKS FROM DBA_DATA_FILES GROUP BY
TABLESPACE_NAME) D,(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) /
(1024 * 1024), 2) FREE_SPACE FROM DBA_FREE_SPACE GROUP BY
TABLESPACE_NAME) F WHERE D.TABLESPACE_NAME =
F.TABLESPACE_NAME(+)UNION ALL SELECT D.TABLESPACE_NAME,SPACE
"SUM_SPACE(M)",BLOCKS SUM_BLOCKS,USED_SPACE "USED_SPACE(M)",
(100-ROUND(NVL(USED_SPACE, 0) / SPACE * 100, 2))
"FREE_RATE(%)",NVL(FREE_SPACE, 0) "FREE_SPACE(M)"FROM (SELECT
TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024), 2)
SPACE,SUM(BLOCKS) BLOCKS FROM DBA_TEMP_FILES GROUP BY
TABLESPACE_NAME) D,(SELECT
TABLESPACE_NAME,ROUND(SUM(BYTES_USED) / (1024 * 1024), 2)
USED_SPACE,ROUND(SUM(BYTES_FREE) / (1024 * 1024), 2) FREE_SPACE FROM
V$TEMP_SPACE_HEADER GROUP BY TABLESPACE_NAME) F WHERE
D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)ORDER BY 5 DESC;
Based on the command output, the vacancy rate of each tablespace.
Step 4 Check the usage of tablespaces.
SQL> select t.segment_name, t.partition_name, t.segment_type,
round(t.bytes/1024/1024) MB, t.tablespace_name from dba_segments t order by MB
desc;
Step 5 Add data files to tablespaces.

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 10


Copyright © Huawei
Technologies Co., Ltd.
IT Auxiliary
Oracle Database Operation Guide Common OperationsCommon Operations

If the data files to be added are file systems or raw devices, ensure that the file systems have sufficient
space or user permission on the raw devices is correct.

SQL> alter tablespace <TABLE_NAME> add datafile '<PATH/FILE_NAME>' size


<FILE_SIZE>G;
Step 6 Increase the sizes of existing data files for tablespaces.
SQL> alter database datafile '<DATAFILE_NAME>' resize <FILE_SIZE>G;
----End

1.11 Collecting Data Table Statistics and Index Statistics


That Have Not Been Analyzed
Collect data table statistics and index statistics that have not been analyzed to ensure that SQL
statement execution plans are correct.

Precautions
Collecting statistics affects database performance. Therefore, collect statistics during low-
traffic hours.

Procedure
Step 1 Log in to the operating system as the oracle user.
Step 2 Connect to the database.
sqlplus '/ as sysdba'
Step 3 Collect data table statistics and index statistics that have not been analyzed.
1. Collect data table statistics.
SQL> exec dbms_stats.gather_table_stats(ownname =>'OWNER', tabname
=>'TABLE_NAME');
2. Collect index statistics.
SQL> exec dbms_stats.gather_schema_stats(ownname =>'OWNER');
----End

Issue 01 (2013-06-30) Huawei Proprietary and Confidential 11


Copyright © Huawei
Technologies Co., Ltd.

You might also like