发布新日志

  • Ora-12516有可能是连接数过多,修改Oracle数据库processes和sessions

    2012-04-18 13:03:28

    1、 plsql连接数据库时,出现

     

    Ora-12516:TSN:监听程序找不到符合协议堆栈要求的可以处理程序

     

     

    2、查看alert_SID.log出现下面的信息

    Process q006 started up but failed with error = 20

    Process q006 started up but failed with error = 20

    Process q006 started up but failed with error = 20

    Process q006 started up but failed with error = 20

     

    3        、查看数据库的当前连接数

    Select * from v$license;

     

    2、 数据库的连接数

    Select * from v$patameter ;

    中的processessessions值接近当前的连接数

     

    如果不修改数据库的连接数,重新数据库也可以解决该问题,但毕竟不是长远之计。

    修改数据库的连接数(sys用户):

     

    SQL> alter system set processes=500 scope=spfile;

     

    System altered.

     

    SQL> show parameter processes

     

    SQL> show parameter sessions

     

    SQL>

    SQL> alter system set sessions=555 scope=spfile;

     

    System altered.

     

    SQL> shutdown abort;

    ORACLE instance shut down.

    SQL> startup

    ORACLE instance started.

     

    Total System Global Area 2625634304 bytes

    Fixed Size                  793464 bytes

    Variable Size            456385672 bytes

    Database Buffers        2164260864 bytes

    Redo Buffers               4194304 bytes

    Database mounted.

    Database opened.

    SQL>

    SQL> show parameter processes

     

    NAME                                TYPE       VALUE

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

    aq_tm_processes                     integer    0

    db_writer_processes                 integer    2

    gcs_server_processes                integer    0

    job_queue_processes                 integer    10

    log_archive_max_processes           integer    2

    processes                           integer    500

    SQL> show parameter sessions

     

    NAME                                TYPE       VALUE

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

    java_max_sessionspace_size          integer    0

    java_soft_sessionspace_limit        integer    0

    license_max_sessions                integer    0

    license_sessions_warning            integer    0

    logmnr_max_persistent_sessions      integer    1

    session_cached_cursors              integer    0

    session_max_open_files              integer    10

    sessions                            integer    555

    shared_server_sessions              integer

    SQL> create pfile from spfile;

     

    File created.
  • 【转】oracle pfile和spfile小结

    2012-04-18 13:02:25

    1、pfile 文本文件 client端参数文件;不能动态修改,可以用普通的编辑器修改,修改之后需要重启。pfile可能会导致服务器启动不一致,因为可以在客户端启动。 2、spfile 二进制文件服务器端参数文件,有了spfile,oracle可以实现动态参数在线修改,部分参数修改之后无需重启。但是,因为是二进制文件,所以不能用 普通的编辑器修改,要用alter命令从sql里面来修改。spfile保证服务器每次的启动都是一致的。只有spfile而没有pfile文件时,可以 通过: create pfile='位置+名字' from spfile; 如: create pfile='E:/ORACLE/PRODUCT/10.2.0/DB_1/DBS/spfileorcl_bak.ora' from spfile; 进行创建pfile文件。 同理,只有pfile而没有spfile时,可以通过: create spfile='位置+名字' from pfile; 进行创建spfile文件。pfile和spfile二者可以互相备份。 3、通过spfile或pfile启动数据库: (1)startup nomount启动方式,查找文件的顺序是 spfileSID.ora-〉spfile.ora-〉initSID.ora-〉init.ora(spfile优先于pfile)。 (2)startup pfile='文件目录'----通过pfile文件启动;(3)startup spfile='文件目录'----通过spfile文件启动。 以下转自: http://www.cnblogs.com/jacktu/archive/2008/02/27/1083232.html 查看系统是以pfile还是spfile启动 Select isspecified,count(*) from v$spparameter group by isspecified; 如果isspecified里有true,表明用spfile进行了指定配置 如果全为false,则表明用pfile启动 使用SPfile的好处 Spfile改正了pfile管理混乱的问题,在多结点的环境里,pfile会有多个image 启动时候需要跟踪最新的image。这是个烦琐的过程。 用spfile以后,所有参数改变都写到spfile里面(只要定义scope=spfile或both),参数配置有个权威的来源。 查看spfile location show parameter spfile 从spfile获取pfile Create pfile='d:pfileSID.ora' from spfile; Create pfile='d:pfileSID.ora' from spfile='spfile_location'; 从pfile获取spfile Create spfile from pfile='Your_pfile_location' Create spfile='spfile_location' from pfile='Your_pfile_location' 动态修改参数 alter system set parameter=Value scope=spfile|both|memory Startup nomount的时候需要读去spfile或pfile,两者共存,spfile优先 强制用pfile启动 SQL>startup pfile='Your_Pfile.ora' startup spfile='/data/oracle/product/10.2.0/db_1/dbs/dbs/spfile_mqq.ora' force 通过pfile连接到spfile启动 修改pfile文件

     

    oracle pfile spfiel 总结
    2008-08-17 11:43

       ORACLE SPFILE PFILE 总结

    OS:Linux localhost.localdomain 2.4.21-20.EL #1 Wed Aug 18 20:58:25 EDT 2004 i686 i686 i386 GNU/Linux

    ORACLE:
    SQL> select*from v$version;

    BANNER
    ----------------------------------------------------------------
    Oracle9i Release 9.2.0.4.0 - Production
    PL/SQL Release 9.2.0.4.0 - Production
    CORE    9.2.0.3.0       Production
    TNS for Linux: Version 9.2.0.4.0 - Production
    NLSRTL Version 9.2.0.4.0 - Production


    1。指定PFILE的路径:
    CREATE SPFILE FROM PFILE='初始化变量文件的全路径';

    CREATE SPFILE [= '<spfile_name>;'] FROM PFILE [= '<pfile_name>;'];

    The above will create a Server Parameter file (SPFILE) based on the existing
    Parameter File (PFILE) (INIT<ORACLE_SID>;.ORA).
    The SPFILE is by default named SPFILE<ORACLE_SID>;.ORA and placed in the default (port specific) directory.

    If existing PFILE (INIT<ORACLE_SID>;.ORA) is not in default directory and using default naming,
    the below must be specified:
    CREATE SPFILE FROM PFILE='<directory-and-filename>;' ;

    SQL> create spfile='/opt/oracle/admin/boco/pfile/spfileorcl.ora' from pfile='/opt/oracle/admin/boco/pfile/initorcl.ora.716200815553';

       File created.

       SQL> show parameter process;

       NAME                                 TYPE        VALUE
       ------------------------------------ ----------- ------------------------------
       aq_tm_processes                      integer     1
       db_writer_processes                  integer     1
       job_queue_processes                  integer     10
       log_archive_max_processes            integer     2
       processes                            integer     50
       SQL> shutdown immediate;
       Database closed.
       Database dismounted.
       ORACLE instance shut down.
       SQL> startup
       ORACLE instance started.

       Total System Global Area 236000356 bytes
       Fixed Size                   451684 bytes
       Variable Size             201326592 bytes
       Database Buffers           33554432 bytes
       Redo Buffers                 667648 bytes
       Database mounted.
       Database opened.
       SQL> show parameter process;

       NAME                                 TYPE        VALUE
       ------------------------------------ ----------- ------------------------------
       aq_tm_processes                      integer     1
       db_writer_processes                  integer     1
       job_queue_processes                  integer     10
       log_archive_max_processes            integer     2
       processes                            integer     150
       SQL> create spfile from pfile='/opt/oracle/admin/boco/pfile/initorcl.ora.716200815553'
        2 ;
       create spfile from pfile='/opt/oracle/admin/boco/pfile/initorcl.ora.716200815553'
       *
       ERROR at line 1:
       ORA-32002: cannot create SPFILE already being used by the instance


       SQL> shutdown immediate
       Database closed.
       Database dismounted.
       ORACLE instance shut down.
       SQL> startup pfile='/opt/oracle/admin/boco/pfile/initorcl.ora.716200815553';
       ORACLE instance started.

       Total System Global Area 236000356 bytes
       Fixed Size                   451684 bytes
       Variable Size             201326592 bytes
       Database Buffers           33554432 bytes
       Redo Buffers                 667648 bytes
       Database mounted.
       Database opened.
       SQL> create spfile from pfile='/opt/oracle/admin/boco/pfile/initorcl.ora.716200815553'
        2 ;

       File created.


    3.在pfile中可以指定引用spfile,
    启动时会先用pfile指定的参数,然后如果spfile中有相同的参数覆盖pfile中的参数
    你可以在pfile中指定引用spfile
    如,你可以在pfile中加入如下一行:

    spfile='/opt/oracle/dbs/spfile<sid>.ora'

    4.查看当前数据库是pfile还是spfile启动
    oracle在默认情况下以spfile启动,除非你启动时指定pfile
    如:startup pfile=/opt/oracle/admin/boco/pfile/initorcl.ora

    show parameter spfile;如果是不为空,会告诉你spfile的文件路径,说明是以spfile启动。如下面例子

    SQL> startup pfile=/opt/oracle/admin/boco/pfile/initorcl.ora.716200815553
       ORACLE instance started.

       Total System Global Area 236000356 bytes
       Fixed Size                   451684 bytes
       Variable Size             201326592 bytes
       Database Buffers           33554432 bytes
       Redo Buffers                 667648 bytes
       Database mounted.
       Database opened.
       SQL> show parameter process;

       NAME                                 TYPE        VALUE
       ------------------------------------ ----------- ------------------------------
       aq_tm_processes                      integer     1
       db_writer_processes                  integer     1
       job_queue_processes                  integer     10
       log_archive_max_processes            integer     2
       processes                            integer     50
       SQL> show parameter spfile;

       NAME                                 TYPE        VALUE
       ------------------------------------ ----------- ------------------------------
       spfile                               string
       SQL> show parameter pfile;

       NAME                                 TYPE        VALUE
       ------------------------------------ ----------- ------------------------------
       spfile                               string

  • mysql 8小时空闲后连接超时的问题

    2011-10-13 10:57:23

    近一段时间,部门同事反映在使用mysql的过程出现数据库连接问题

    应用程序和数据库建立连接,如果超过8小时应用程序不去访问数据库,数据库就断掉连接 。这时再次访问就会抛出异常,如下所示:

    java.io.EOFException
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
    ...

    查了一下发现应用程序和mysql数据库建立连接,如果超过8小时应用程序不去访问数据库,数据库就断掉连接 。这时再次访问就会抛出异常。

    关于mysql自动断开的问题研究结果如下,在mysql中有相关参数设定,当数据库连接空闲一定时间后,服务器就会断开等待超时的连接:
    1、相关参数,红色部分
    mysql> show variables like '%timeout%';
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | connect_timeout          | 5     |
    | delayed_insert_timeout   | 300   |
    | innodb_lock_wait_timeout | 50    |
    | interactive_timeout      | 28800 |
    | net_read_timeout         | 30    |
    | net_write_timeout        | 60    |
    | slave_net_timeout        | 3600 |
    | wait_timeout             | 28800 |
    +--------------------------+-------+        
    同一时间,这两个参数只有一个起作用。到底是哪个参数起作用,和用户连接时指定的连接参数相关,缺省情况下是使用wait_timeout。我建议是将这两个参数都修改,以免引起不必要的麻烦。

    2、修改参数
    这两个参数的默认值是8小时(60*60*8=28800)。我测试过将这两个参数改为0,结果出人意料,系统自动将这个值设置为1。换句话说,不能将该值设置为永久。
    将这2个参数设置为24小时(60*60*24=604800)即可。
    set interactive_timeout=604800;
    set wait_timeout=604800;

    也可以修改my.cof,修改后重起mysql
    打开/etc/my.cnf,在属性组mysqld下面添加参数如下:
    [mysqld]
    interactive_timeout=28800000
    wait_timeout=28800000

    如果一段时间内没有数据库访问则mysql自身将切断连接,之后访问java访问连接池时对数据库的数据通道早就关闭了,因为dbcp连接池无法时时维护与数据库的连接关系,mysql5以后即使在dbcp配置中加入autoReconnect=true也没有效果。


    另外一种解决办法是,通过连接池在空闲时自动重新连接解决这个问题,如下是hibernate连接池的实现方法:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- the proxool configuration can be embedded within your own application's.
    Anything outside the "proxool" tag is ignored. -->
    <something-else-entirely>
    <proxool>
    <!-- proxool别名 -->
    <alias>product</alias>
    <!-- 数据库连接Url -->
    <driver-url>jdbc:mysql://db:3306/product?useUnicode=true&amp;characterEncoding=utf8</driver-url>
    <!-- JDBC驱动名称 -->
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <!-- 数据库连接帐卿-->
    <driver-properties>
    <property name="user" value="chinawidth" />
    <property name="password" value="123456" />
    </driver-properties>
    <!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回撿超时的销歿-->
    <house-keeping-sleep-time>90000</house-keeping-sleep-time>
    <!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受 -->
    <maximum-new-connections>20</maximum-new-connections>
    <!-- 最少保持的空闲连接擿-->
    <prototype-count>3</prototype-count>
    <!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-

    connections决定 -->
    <maximum-connection-count>20</maximum-connection-count>
    <!-- 最小连接数 -->
    <minimum-connection-count>3</minimum-connection-count>
    <!-- 在分配连接前后是否进行有效性测试,这个是解决本问题的关钿-->
    <test-before-use>true</test-before-use>
    <test-after-use>true</test-after-use>
    <!-- 用于测试的SQL语句 -->
    <house-keeping-test-sql>SELECT CURRENT_USER</house-keeping-test-sql>
    </proxool>
    </something-else-entirely>


Open Toolbar