Hey!! Sky!

Mar 13, 2006

Oracle 9i 安装出现登台区错误

    今天 Joseph 在安装 Oracle 9i 客户端时出现登台区错误的问题,如图:


点下一步出现:



    由于他的机器上之前安装了 Oracle 8i,是卸载了重新安装的,安装之前路径一栏默认显示的是 8i 的路径,我怀疑是注册表没有删干净导致,可是他说都删了,一看服务上也的确没有有关 Oracle 的服务了。可是搞了半天还是不行,最后求助 google,发现 Itpub 上已经有人问过,一看果然是注册表没有删干净。不知道开始他怎么删的,哈哈哈。一定要把注册表中 LOCAL_MACHINE 下面的 ORACLE 项删掉,然后就能成功安装了。

    看来最基本的安装上问题还是不少,比如:安装文件夹不能是中文等等,在此记一笔,以备日后查询。

Mar 09, 2006

从菜鸟开始解决问题

    下午在公司 PC 上装了 Oracle 9i,除了一个 Agent Service 的问题,一切算是顺利,于是停掉所有 Oracle 服务,开始试着安装补丁,这是第一次安装 Oracle 补丁,不过并没有碰到任何问题,看来 Windows 下安装还是很方便的。


    不过等到全都安装完毕之后,用 sqlplus "/as sysdba" 却怎么也进不去,出现 “ORA-12541:TNS:没有监听器”的错误,这个好解决,是因为监听器的服务没有起来,于是用 lsnrctl start 开启监听器,同时服务也跟着起来了,可是用 sqlplus "/as sysdba" 却还是无法连接上,再试 sqlplus sys/XXX@skydb as sysdba 出现 “ORA-12500:TNS:监听程序无法启动专用服务器进程”的错误,这下弄不明白了。google 了一下,找到了一篇《Oracle新手最常碰到的6个错误及解决方案》文章,里面提到 ORA-12500 错误是因为 OracleService<SID> 服务没起来的缘故。之前一直以为,这个服务无非是方便操作系统重启之后自动打开 Oracle 数据库用的,就好像监听器的服务一样,启动监听器服务也跟这起来了,原来这个服务不起来,数据库是服务打开的,这下终于明白了,于是用 net start OracleServiceSKY 启动服务,然后 sqlplus "/as sysdba" 就成功登陆了,试了下 shutdown immediate 关闭数据库,发现这个服务还是启动的,开来这个服务是打开数据库必须的,但关闭数据库服务并不会停止。上文还提到一些基础的菜鸟问题和解决方法,引用过来:



  1、ORA-12541:TNS:没有监听器
  原因:没有启动监听器或者监听器损坏。若是前者,使用命令net start OracleOraHome81TNSListener(名字可能有出入)即可;如果是后者,则使用“Net8 Configuration Assistant”工具向导之“监听程序配置”增加一个监听器即可(基本不用写任何信息,一路OK。在添加之前可能需要把所有的监听器先删!)


  2、ORA-12500:TNS:监听程序无法启动专用服务器进程或ORA-12560:TNS:协议适配器错误
  原因:ORACLE的数据库服务没有启动。使用命令net start ORACLESERVICEORADB(ORADB为数据库名字)即可。如果仍没有解决,请继续向下看。


  3、如果数据库服务启动失败,则很有可能是其注册表项值损坏,最好的做法是以下两步:
  1)ORADIM -DELETE -SID oradb 删除数据库服务项
  2)ORADIM -NEW -SID oradb 新增数据库服务项
  注:这个过程中如果出错,就重启计算机!


  4、ORA-12154:TNS:能解析服务名
  原因:ORACLE的网络服务名没有正确配置。请使用“Net8 Configuration Assistant”工具向导之“本地网络服务名配置”配置TNS即可。如果仍没有解决,请继续向下看。


  5、ORA-1034 :TNS:ORACLE不可用
  原因:ORACLE的数据库服务正确启动,但是数据库没有打开!
  使用命令:
  1)svrmgrl 启动服务管理器
  2)connect internal 以internal身份登陆
  3)startup 打开数据库


  6、ORA-12560:TNS:协议适配器错误(顽固性的)
  原因:未知。
  解决:必杀技--打开“Windows任务管理器”,杀死ORACLE.exe及ORADIM.exe进程,书写自己的ora_startup.bat,执行之!


  PS:
  1、我的ora_startup.bat:
  net start OracleOraHome81TNSListener
  net start ORACLESERVICEORADB
  svrmgrl 一般情况下不用,不过有时少不了它的,具体步骤见第5步。


  2、我的ora_shutdown.bat:
  net stop OracleOraHome81TNSListener
  net stop ORACLESERVICEORADB


  3、ORACLE相关服务名请参见“管理工具”之“服务”中以ORACLE开头的服务名

Mar 07, 2006

[Guide]Managing Oracle Processes

Server Processes
Dedicated Server Processes
  In the following situations, users and administrators should explicitly connect to an instance using a dedicated server process:
  1.To submit a batch job (for example, when a job can allow little or no idle time for the server process)
  2.To use Recovery Manager to back up, restore, or recover a database

  To request a dedicated server connection when Oracle is configured for shared server, users must connect using a net service name that is configured to use a dedicated server. Specifically, the net service name value should include the SERVER=DEDICATED clause in the connect descriptor.


Shared Server Processes



Configuring Oracle for the Shared Server
Initialization Parameters for Shared Server
Parameter               Description
The following parameter is required by shared server:
DISPATCHERS             配置 dispatcher 进程
The following parameters are optional (if not specified, Oracle selects defaults):
MAX_DISPATCHERS         同时运行的最大 dispatcher 进程数量
SHARED_SERVERS          实例启动时,共享服务器进程的数量
MAX_SHARED_SERVERS      同时运行的最大共享服务器进程的数量
CIRCUITS                Specifies the total number of virtual circuits that are available for inbound and outbound network sessions.
SHARED_SERVER_SESSIONS  Specifies the total number of shared server user sessions to allow. Setting this parameter enables you to reserve user sessions for dedicated servers.
Other parameters affected by shared server that may require adjustment:
LARGE_POOL_SIZE         Specifies the size in bytes of the large pool allocation heap. Shared server may force the default value to be set too high, causing performance problems or problems starting the database.
SESSIONS                Specifies the maximum number of sessions that can be created in the system. May need to be adjusted for shared server.
 
Setting the Initial Number of Dispatchers (DISPATCHERS)
  如果1个dispatcher可以供1000个连接同时使用,那么当高峰时期有1500个连接的环境中,应该将dispatcher设为2个。太多的dispatcher会降低系统性能。


Setting the Initial Number of Shared Servers (SHARED_SERVERS)
  Oracle 会根据请求队列的长度动态调整共享服务器进程的数量,范围在SHARED_SERVERS和MAX_SHARED_SERVERS之间。
  Typical systems seem to stabilize at a ratio of one shared server for every ten connections.


Adding and Removing Dispatcher Processes
  查看 V$QUEUE, V$DISPATCHER and V$DISPATCHER_RATE 视图,如果 dispatcher processes 负担一直很高,则增加进程(最多增加到 MAX_DISPATCHERS),反之减少他们。
  当减少进程时,Dispatcher Processes 不会立即移除,而是等到用户断开连接才会终止。
语法:
ALTER SYSTEM
SET DISPATCHERS =
'(PROTOCOL=TCP)(DISPATCHERS=5) (INDEX=0)',
'(PROTOCOL=TCPS)(DISPATCHERS=2) (INDEX=1)';
The INDEX keyword can be used to identify which DISPATCHERS parameter to modify. To identify the index number assigned to an DISPATCHERS parameter, query the CONF_INDX value in the V$DISPATCHER view.


Shutting Down Specific Dispatcher Processes
  Each dispatcher is uniquely identified by a name of the form Dnnn.可以通过 V$DISPATCHER 查询。

To shut down dispatcher D002, issue the following statement:
ALTER SYSTEM SHUTDOWN IMMEDIATE 'D002';

  The IMMEDIATE keyword stops the dispatcher from accepting new connections and Oracle immediately terminates all existing connections through that dispatcher. After all sessions are cleaned up, the dispatcher process shuts down. If IMMEDIATE were not specified, the dispatcher would wait until all of its users disconnected and all of its connections terminated before shutting down.


Changing the Minimum Number of Shared Server Processes
  当实例启动,可以动态调整共享服务器进程数量。Oracle will eventually terminate servers that are idle when there are more shared servers than the minimum limit you specify.
  If you set SHARED_SERVERS to 0, Oracle terminates all current servers when they become idle and does not start any new servers until you increase SHARED_SERVERS. Thus, setting SHARED_SERVERS to 0 may be used to effectively disable shared server.
语法:
ALTER SYSTEM SET SHARED_SERVERS = 2;


Monitoring Shared Server
V$DISPATCHER
  Provides information on the dispatcher processes, including name, network address, status, various usage statistics, and index number.
V$DISPATCHER_RATE
  Provides rate statistics for the dispatcher processes.
V$QUEUE
  Contains information on the shared server message queues.
V$SHARED_SERVER
  Contains information on the shared server processes.
V$CIRCUIT
  Contains information about virtual circuits, which are user connections to the database through dispatchers and servers.
V$SHARED_SERVER_MONITOR
  Contains information for tuning shared server.
V$SGA
  Contains size information about various system global area (SGA) groups. May be useful when tuning shared server.
V$SGASTAT
  Detailed statistical information about the SGA, useful for tuning.
V$SHARED_POOL_RESERVED
  Lists statistics to help tune the reserved pool and space within the shared pool.
 


About Oracle Background Processes



Monitoring the Processes of an Oracle Instance
Process and Session Views

V$PROCESS
  Contains information about the currently active processes
V$SESSION
  Lists session information for each current session
V$SESS_IO
  Contains I/O statistics for each user session
V$SESSION_LONGOPS
  This view displays the status of various operations that run for longer than 6 seconds (in absolute time). These operations currently include many backup and recovery functions, statistics gathering, and query execution. More operations are added for every Oracle release.
V$SESSION_WAIT
  Lists the resources or events for which active sessions are waiting
V$SYSSTAT
  Contains session statistics
V$RESOURCE_LIMIT
  Provides information about current and maximum global resource utilization for some system resources
V$SQLAREA
  Contains statistics about shared SQL area and contains one row for each SQL string. Also provides statistics about SQL statements that are in memory, parsed, and ready for execution
V$LATCH
  Contains statistics for non-parent latches and summary statistics for parent latches
 
Monitoring Locks
V$LOCK
  Lists the locks currently held by the Oracle server and outstanding requests for a lock or latch
 
Trace Files and the Alert File
  The alert file of a database is a chronological log of messages and errors, which includes the following:
  1.All internal errors (ORA-600), block corruption errors (ORA-1578), and deadlock errors (ORA-60) that occur
  2.Administrative operations, such as CREATE, ALTER, and DROP statements and STARTUP, SHUTDOWN, and ARCHIVELOG statements
  3.Several messages and errors relating to the functions of shared server and dispatcher processes
  4.Errors occurring during the automatic refresh of a materialized view
  5.The values of all initialization parameters at the time the database and instance start

  If an operation is successful, a "completed" message is written in the alert file, along with a timestamp.


Controlling the Size of Trace Files
  You can control the maximum size of all trace files (excluding the alert file) using the initialization parameter MAX_DUMP_FILE_SIZE. This limit is set as a number of operating system blocks. To control the size of an alert file, you must manually delete the file when you no longer need it; otherwise Oracle continues to append to the file. You can safely delete the alert file while the instance is running, although you might want to make an archived copy of it first.



Managing Processes for Parallel Execution
  The degree of parallelism is the number of parallel execution servers that can be associated with a single operation. The degree of parallelism is determined by any of the following:
  1.A PARALLEL clause in a statement
  2.For objects referred to in a query, the PARALLEL clause that was used when the object was created or altered
  3.A parallel hint inserted into the statement
  4.A default determined by Oracle


Managing the Parallel Execution Servers
  Parallel execution can be tuned for you automatically by setting the initialization parameter PARALLEL_AUTOMATIC_TUNING = TRUE. With this setting, Oracle determines the default values for other initialization parameters that affect the performance of parallel execution.


Altering Parallel Execution for a Session
Disabling Parallel Execution

  All subsequent DML (INSERT, UPDATE, DELETE), DDL (CREATE, ALTER), or query (SELECT) statements will not be parallelized after an ALTER SESSION DISABLE PARALLEL DML|DDL|QUERY statement is issued. They will be executed serially, regardless of any PARALLEL clause or parallel hints associated with the statement.


Enabling Parallel Execution
  Where a PARALLEL clause or parallel hint is associated with a statement, those DML, DDL, or query statements will execute in parallel after an ALTER SESSION ENABLE PARALLEL DML|DDL|QUERY statement is issued. This is the default for DDL and query statements.

  A DML statement can be parallelized only if you specifically issue this statement. The following statement enables parallel processing of DML statements:
ALTER SESSION ENABLE PARALLEL DML;
Note:
  Parallel DML is available only if you have installed Oracle's Partitioning Option.


Forcing Parallel Execution
  You can force parallel execution of all subsequent DML, DDL, or query statements for which parallelization is possible with the ALTER SESSION FORCE PARALLEL DML|DDL|QUERY statement. Additionally you can force a specific degree of parallelism to be in effect, overriding any PARALLEL clause associated with subsequent statements. If you do not specify a degree of parallelism in this statement, the default degree of parallelism is used. However, a degree of parallelism specified in a statement through a hint will override the degree being forced.

  The following statement forces parallel execution of subsequent statements and sets the overriding degree of parallelism to 5:
ALTER SESSION FORCE PARALLEL DDL PARALLEL 5;

  To force the parallelization of DML, it must also be enabled as shown in "Enabling Parallel Execution".



Managing Processes for External Procedures
  External procedures, are procedures that are called from another program, but are written in a different language.

  To control access to DLLs, the database administrator grants execute privileges for the appropriate DLLs to application developers. The application developers write the external procedures and grant execute privilege on specific external procedures to other users.



Terminating Sessions
  When a session is terminated, the session's transaction is rolled back and resources (such as locks and memory areas) held by the session are immediately released and available to other sessions.


Identifying Which Session to Terminate
  To identify the system identifier (sid) and serial number of a session, query the V$SESSION dynamic performance view.
  当该用户在执行 SQL 时 STATUS 栏为 ACTIVE,否则为 INACTIVE。


Terminating an Active Session
  If a user session is processing a transaction (ACTIVE status) when it is terminated, the transaction is rolled back and the user immediately receives the following message:
ORA-00028: your session has been killed


  If, after receiving the ORA-00028 message, a user submits additional statements before reconnecting to the database, Oracle returns the following message:
ORA-01012: not logged on


  If an active session cannot be interrupted (it is performing network I/O or rolling back a transaction), the session cannot be terminated until the operation completes. Additionally, the session that issues the ALTER SYSTEM statement to terminate a session waits up to 60 seconds for the session to be terminated. If the operation that cannot be interrupted continues past one minute, the issuer of the ALTER SYSTEM statement receives a message indicating that the session has been "marked" to be terminated. A session marked to be terminated is indicated in V$SESSION with a STATUS of KILLED and a SERVER that is something other than PSEUDO.


Terminating an Inactive Session
  If the session is INACTIVE when it is terminated, the ORA-00028 message is not returned immediately. The message is not returned until the user subsequently attempts to use the terminated session.


  When an inactive session has been terminated, STATUS in the V$SESSION view is KILLED. The row for the terminated session is removed from V$SESSION after the user attempts to use the session again and receives the ORA-00028 message.

[Guide]Starting Up and Shutting Down

Using SQL*Plus to Start Up a Database
Oracle locates your initialization parameter file by examining filenames in the following order:
  1.spfile$ORACLE_SID.ora
  2.spfile.ora (in a Real Application Clusters environment one server parameter file is used to store the initialization parameter settings for all instances)
  3.init$ORACLE_SID.ora


You cannot start a database instance if you are connected to the database through a shared server process.



Starting an Instance and Mounting a Database
Mount 状态下可以做以下工作:
  1.Renaming datafiles
  2.Adding, dropping, or renaming redo log files
  3.Enabling and disabling redo log archiving options
  4.Performing full database recovery
 
Restricting Access to a Database at Startup
RESTRICT 状态下可以做的工作:
  1.Perform an export or import of database data
  2.Perform a data load (with SQL*Loader)
  3.Temporarily prevent typical users from using data
  4.During certain migration and upgrade operations


Forcing an Instance to Start
何时使用 STARTUP FORCE
  1.You cannot shut down the current instance with the SHUTDOWN NORMAL, SHUTDOWN IMMEDIATE, or SHUTDOWN TRANSACTIONAL commands.
  2.You experience problems when starting an instance.


If an instance is running, STARTUP FORCE shuts it down with mode ABORT before restarting it.



Altering Database Availability
Opening a Database in Read-Only Mode
  While opening a database in read-only mode guarantees that datafile and redo log files are not written to, it does not restrict database recovery or operations that change the state of the database without generating redo.


  If a query against a database in read-only mode uses temporary tablespace, for example to do disk sorts, then the issuer of the query must have a locally managed tablespace assigned as the default temporary tablespace. Otherwise, the query will fail.


Note:
You cannot use the RESETLOGS clause with a READ ONLY clause.



Quiescing a Database
  This quiesced state allows you or other administrators to perform actions that cannot safely be done otherwise. These actions are categorized as follows:
  1.Actions that can fail if concurrent user transactions access the same object.
  2.Actions whose undesirable intermediate effect can be seen by concurrent user transactions.


Note:
  For this release of Oracle9i, in the quiesce database context a DBA is defined as user SYS or SYSTEM. Other users, including those with the DBA role are not allowed to issue the ALTER SYSTEM QUIESCE DATABASE statement or proceed after the database is quiesced.
 
Placing a Database into a Quiesced State
ALTER SYSTEM QUIESCE RESTRICTED;


  Any non-DBA active sessions will proceed until they become inactive. An active session is defined as a session that is currently inside of a transaction, a query, a fetch, or a PL/SQL statement; or a session that is currently holding any shared resources (for example, enqueues). No inactive sessions are allowed to become active. If a user, for example, issues a SQL query in an attempt to force an inactive session to become active, the query will appear to be hung. When the database is later unquiesced, the session is resumed, and the blocked action (for example, the previously mentioned SQL query) will be processed.


  Once all non-DBA sessions become inactive, the ALTER SYSTEM QUIESCE RESTRICTED statement finishes, and the database is considered as in a quiesced state. In an Oracle Real Application Clusters environment, this statement affects all instances, not just the one that issues the statement.


Note:
  You must have the Database Resource Manager feature activated, and it must have been activated since instance startup (all instances in an Oracle Real Application Clusters environment) to successfully issue the ALTER SYSTEM QUIESCE RESTRICTED statement. It is through the facilities of the Database Resource Manager that non-DBA sessions are prevented from becoming active. Also, while this statement is in effect, any attempt to change the current resource plan will be queued until after the system is unquiesced.


  The ALTER SYSTEM QUIESCE RESTRICTED statement may wait a long time for active sessions to become inactive. If you interrupt the request, or if your session abnormally terminates for some reason before all active sessions are quiesced, Oracle will automatically undo any partial effects of the statement.


  If a query is carried out by successive multiple Oracle Call Interface (OCI) fetches, the ALTER SYSTEM QUIESCE RESTRICTED statement does not wait for all fetches to finish; it only waits for the current fetch to finish.


  For both dedicated and shared server connections, all non-DBA logins after this statement is issued are queued by the Database Resource Manager, and are not allowed to proceed. To the user, it appears as if the login is hung. The login will resume when the database is unquiesced.


  The database remains in the quiesced state even if the session that issued the statement exits. A DBA must log in to the database to issue the statement that specifically unquiesces the database.


  While in the quiesced state, you cannot use file system copy to backup the database's datafiles as cold backups, even if you do a checkpoint on every instance. The reason for this is that in the quiesced state the file headers of online datafiles continue to look like they are being accessed. They do not look the same as if a clean shutdown were done. Similarly, to perform a hot backup of the datafiles of any online tablespace while the database is in a quiesced state, you are still required to first place the tablespace into backup mode using the ALTER TABLESPACE... BEGIN BACKUP statement.


Restoring the System to Normal Operation
ALTER SYSTEM UNQUIESCE;


  All non-DBA activity is allowed to proceed. In an Oracle Real Application Clusters environment, this statement is not required to be issued from the same session, or even the same instance, as that which imposed the quiesce state. If the session issuing the ALTER SYSTEM UNQUIESCE statement should terminate abnormally, the Oracle database server ensures that the unquiesce operation finishes.


Viewing the Quiesce State of an Instance
  The V$INSTANCE view can be queried to see the current state of an instance. It contains a column named ACTIVE_STATE, whose values are shown in the following table:
ACTIVE_STATE    Description
NORMAL          Normal unquiesced state
QUIESCING       Being quiesced, but there are still active non-DBA sessions running
QUIESCED        Quiesced, no active non-DBA sessions are active or allowed
 


Suspending and Resuming a Database
  The ALTER SYSTEM SUSPEND statement suspends a database by halting all input and output (I/O) to datafiles (file header and file data) and control files, thus allowing a database to be backed up without I/O interference. When the database is suspended all preexisting I/O operations are allowed to complete and any new database accesses are placed in a queued state.


  In an Oracle Real Application Clusters environment, if the suspend command is entered on one system, all active instances in a given cluster are quiesced.  However, do not start a new instance while you suspend another instance, since the new instance will not be suspended.


  Use the ALTER SYSTEM RESUME statement to resume normal database operations. You can specify the SUSPEND and RESUME from different instances.


  The suspend/resume feature is useful in systems that allow you to mirror a disk or file and then split the mirror, providing an alternative backup and restore solution. If you use a system that is unable to split a mirrored disk from an existing database while writes are occurring, then you can use the suspend/resume feature to facilitate the split.


  The suspend/resume feature is not a suitable substitute for normal shutdown operations, however, since copies of a suspended database can contain uncommitted updates.


Caution:
  Do not use the ALTER SYSTEM SUSPEND statement as a substitute for placing a tablespace in hot backup mode. Precede any database suspend operation by an ALTER TABLESPACE BEGIN BACKUP statement.


语法:
ALTER SYSTEM SUSPEND;
ALTER SYSTEM RESUME;


V$INSTANCE 中 DATABASE_STATUS 显示处于哪种状态:
DATABASE_STATUS
SUSPENDED
ACTIVE

Eygle 的 DBA 生存之四大守则

    Eygle 曾在他发表的文章中多次提到他总结的 DBA 生存之四大守则,但一直没有完整的说明哪四条,今天上去一看终于完整的写出来了,看来很多人也都很关心是哪四条,下面引用一下,如 eygle 所说,和诸位 DBA 朋友共勉。


1.备份重于一切
    我们必需知道,系统总是要崩溃的,没有有效的备份只是等哪一天死!我经常开玩笑的说,唯一会使DBA在梦中惊醒的就是,没有有效的备份.


2.三思而后行
think thrice before you act


    任何时候都要清楚你所做的一切,否则宁可不做!有时候一个回车,一条命令就会造成不可恢复的灾难,所以,你必需清楚确认你所做的一切,并且在必要时保护现场.


3.rm是危险的
    要知道在UNIX/Linux下,这个操作意味着你可能将永远失去后面的东西,所以,确认你的操作!!!
    太多的人在 "rm -rf" (Sky 注:-r 将目录和目录下的文件都删除,包括子目录,-f 删除时不逐一提醒,即使是只读文件)上悲痛欲绝,当年写下这条守则时,是一个凌晨被一个朋友吵醒,他说误操作rm -rf删除掉了200G的数据库,并且没有备份.


我当时能告诉他的只有一句话:要保持冷静.


4.你来制定规范
    良好的规范是减少故障的基础。所以,做为一个DBA,你需要来制订规范,规范开发甚至系统人员,这样甚至可以规避有意或是无意的误操作.减少数据库的风险.


我们知道,在管理良好的数据库服务器上,rm -rf甚至可能是不允许使用的.