由Swap故障引起的ORA-01034: ORACLE not available ORA-27102: out of memory 问题

Oracle数据突然连不上,提示如下,最初以为是sga_memory_target出问题,连上去查看一样出错

[oracle@oracle:/home/oracle]$sqlplus 'roobbin/"ran0.123456"@121.37.158.xx:1521/orcl'

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 10:51:15 2020

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

ERROR:
ORA-01034: ORACLE not available
ORA-27102: out of memory
Linux-x86_64 Error: 12: Cannot allocate memory
Additional information: 26
Additional information: 458753
Additional information: 1627389952
Process ID: 0
Session ID: 0 Serial number: 0

如下

[oracle@oracle:/home/oracle]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 10:51:48 2020

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

Connected to an idle instance.

SQL> show parameter sga;
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0


SQL> exit

尝试进入mount一样无果

[oracle@oracle:/home/oracle]$sqlplus /nolog          

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 10:55:53 2020

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

SQL> conn / as sysdba
Connected to an idle instance.
SQL> show paramater sga;
SP2-0158: unknown SHOW option "paramater"
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0


SQL> shutdown immediate;
ORA-01034: ORACLE not available
ORA-27102: out of memory
Linux-x86_64 Error: 12: Cannot allocate memory
Additional information: 26
Additional information: 458753
Additional information: 1627389952
SQL> startup mount;
ORA-00845: MEMORY_TARGET not supported on this system
SQL> exit
Disconnected

随后出现了这个提示

SQL> startup mount;
ORA-00845: MEMORY_TARGET not supported on this system

刚开始不知道这个提示是由于swap没了导致。折腾了很久去看内存发现swap没了

root@oracle datax-web-2.1.2]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3788        1708         122         892        1958         949
Swap:             0           0           0

随后把swap加上数据库立马就恢复正常了,添加命令如下

[root@oracle datax-web-2.1.2]# dd if=/dev/zero of=/swapfile bs=1024 count=4194304
4194304+0 records in
4194304+0 records out
4294967296 bytes (4.3 GB) copied, 25.8686 s, 166 MB/s
[root@oracle datax-web-2.1.2]# mkswap /swapfile 
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=f0d30855-a3a0-4b09-85ff-f5a393059382
[root@oracle datax-web-2.1.2]# swap
swaplabel  swapoff    swapon     
[root@oracle datax-web-2.1.2]# swapon /swapfile 
swapon: /swapfile: insecure permissions 0644, 0600 suggested.
[root@oracle datax-web-2.1.2]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        1.7G        154M        892M        1.9G        934M
Swap:          4.0G          0B        4.0G

加完后在连上数据库就正常了

[oracle@oracle:/home/oracle]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 11:42:00 2020

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter sga;

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
lock_sga                 boolean     FALSE
pre_page_sga                 boolean     FALSE
sga_max_size                 big integer 1520M
sga_target                 big integer 0
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

做完吧swap加入fstab里面去。也不知道为啥swap突然就没了