【OS】Linux下/dev/shm的作用及ORA-00845錯誤的處理

lhrbest發表於2017-07-27

【OS】Linux下/dev/shm的作用




對/dev/shm認識

一、/dev/shm理論
/dev/shm/是linux下一個非常有用的目錄,因為這個目錄不在硬碟上,而是在記憶體裡。因此在linux下,就不需要大費周折去建ramdisk,直接使用/dev/shm/就可達到很好的優化效果。 /dev /shm/需要注意的一個是容量問題,在linux下,它預設最大為記憶體的一半大小,使用df -h命令可以看到。但它並不會真正的佔用這塊記憶體,如果/dev/shm/下沒有任何檔案,它佔用的記憶體實際上就是0位元組;如果它最大為1G,裡頭放有 100M檔案,那剩餘的900M仍然可為其它應用程式所使用,但它所佔用的100M記憶體,是絕不會被系統回收重新劃分的,否則誰還敢往裡頭存檔案呢?

預設系統就會載入/dev/shm ,它就是所謂的tmpfs,有人說跟ramdisk(虛擬磁碟),但不一樣。象虛擬磁碟一樣,tmpfs 可以使用您的 RAM,但它也可以使用您的交換分割槽來儲存。而且傳統的虛擬磁碟是個塊裝置,並需要一個 mkfs 之類的命令才能真正地使用它,tmpfs 是一個檔案系統,而不是塊裝置;您只是安裝它,它就可以使用了。
  tmpfs有以下優勢:
  1,動態檔案系統的大小。
  2,tmpfs 的另一個主要的好處是它閃電般的速度。因為典型的 tmpfs 檔案系統會完全駐留在 RAM 中,讀寫幾乎可以是瞬間的。
  3,tmpfs 資料在重新啟動之後不會保留,因為虛擬記憶體本質上就是易失的。所以有必要做一些指令碼做諸如載入,繫結的操作。

二、修改/dev/shm大小
預設的最大一半記憶體大小在某些場合可能不夠用,並且預設的inode數量很低一般都要調高些,這時可以用mount命令來管理它。
#mount -o size=1500M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm
在2G的機器上,將最大容量調到1.5G,並且inode數量調到1000000,這意味著大致可存入最多一百萬個小檔案。

如果需要永久修改/dev/shm的值,需要修改/etc/fstab
tmpfs /dev/shm tmpfs defaults,size=1.5G 0 0
#mount -o remount /dev/shm

三、/dev/shm應用
  首先在/dev/shm建個tmp資料夾,然後與實際/tmp繫結
  #mkdir /dev/shm/tmp
  #chmod 1777 /dev/shm/tmp
  #mount –bind /dev/shm/tmp /tmp(–bind )
  在使用mount –bind olderdir newerdir命令來掛載一個目錄到另一個目錄後,newerdir的許可權和所有者等所有資訊會發生變化。掛載後的目錄繼承了被掛載目錄的所有屬性,除了名稱。Oracle 11g的amm記憶體管理模式就是使用/dev/shm,所以有時候修改MEMORY_TARGET或者MEMORY_MAX_TARGET會出現ORA-00845的錯誤




ORA-00845: MEMORY_TARGET not supported on this system

在Oracle 11g中如果採用AMM記憶體管理,那麼當MEMORY_TARGET的值大於/dev/shm的時候,就會報ORA-00845: MEMORY_TARGET not supported on this system錯誤,解決辦法增加/dev/shm大小,在redhat系列系統中,/dev/shm的預設值是系統總記憶體的一半

1、錯誤重現

SQL>SELECT *  FROM V$VERSION;
 
BANNER
——————————————————————————–
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production
PL/SQL Release 11.2.0.3.0 – Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 – Production
NLSRTL Version 11.2.0.3.0 – Production
 
SQL>show parameter memory;
 
NAME                                 TYPE        VALUE
———————————— ———– ——————————
hi_shared_memory_address             integer     0
memory_max_target                    big integer 500M
memory_target                        big integer 500M
shared_memory_address                integer     0
SQL>alter system set memory_max_target=800m;
alter system set memory_max_target=800m
                 *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified
 
 
SQL>alter system set memory_max_target=800m scope=spfile;
 
System altered.
 
SQL>alter system set memory_target=800m scope=spfile; 
 
System altered.
 
SQL>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@xifenfei admin]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 5 19:01:18 2011
 
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
 
Connected to an idle instance.
 
SQL>startup
ORA-00845: MEMORY_TARGET not supported on this system
SQL>!oerr ora 845
00845, 00000, "MEMORY_TARGET not supported on this system"
// *Cause: The MEMORY_TARGET parameter was not supported on this operating system or /dev/shm was not sized correctly on Linux.
// *Action: Refer to documentation for a list of supported operating systems. Or, size /dev/shm to be at least the SGA_MAX_SIZE on each Oracle instance running on the system.

2、修改/dev/shm大小


[root@xifenfei ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_xifenfei-lv_root
                       17G   13G  3.9G  77% /
tmpfs                 590M     0  590M   0% /dev/shm
/dev/sda1             485M   30M  430M   7% /boot
[root@xifenfei ~]# mount -o size=900M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm
[root@xifenfei ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_xifenfei-lv_root
                       17G   13G  3.9G  77% /
tmpfs                 900M     0  900M   0% /dev/shm
/dev/sda1             485M   30M  430M   7% /boot
[root@xifenfei ~]# vi /etc/fstab 
 
 
#
# /etc/fstab
# Created by anaconda on Sat Nov  5 02:49:30 2011
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_xifenfei-lv_root /                       ext4    defaults        1 1
UUID=7ace6c04-d232-43ac-9ef5-70ea92fe49bd /boot                   ext4    defaults        1 2
/dev/mapper/vg_xifenfei-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults,size=900M        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0


3、啟動資料庫驗證

[oracle@xifenfei admin]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 5 19:03:51 2011
 
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
sys@XFF>show parameter memory;
 
NAME                                 TYPE        VALUE
———————————— ———– ——————————
hi_shared_memory_address             integer     0
memory_max_target                    big integer 800M
memory_target                        big integer 800M
shared_memory_address                integer     0


4、官方解釋
Starting with Oracle Database 11g, the Automatic Memory Management feature requires more shared memory (/dev/shm)and file descriptors. The size of the shared memory should be at least the greater of MEMORY_MAX_TARGET and MEMORY_TARGET for each Oracle instance on the computer. If MEMORY_MAX_TARGET or MEMORY_TARGET is set to a non zero value, and an incorrect size is assigned to the shared memory, it will result in an ORA-00845 error at startup.

5、解決問題建議
5.1. If you are installing Oracle 11g on a Linux system, note that Memory Size (SGA and PGA), which sets the initialization parameter MEMORY_TARGET or MEMORY_MAX_TARGET, cannot be greater than the shared memory filesystem (/dev/shm) on your operating system. To resolve the current error, increase the /dev/shm file size.

5.2. If configuring AMM is not possible due to lack of space on /dev/shm mount point, you can configure ASMM instead of AMM, i.e. set SGA_TARGET, SGA_MAX_SIZE and PGA_AGGREGATE_TARGET instead of MEMORY_TARGET.

在redhat6中,修改了fstab中修改後,不能生效,需要重新掛載
vi /etc/fstab
tmpfs /dev/shm tmpfs defaults,size=900M 0 0

vi /etc/rc.local
mount -o remount /dev/shm





 linux下/dev/shm的大小引發ORA-00845: MEMORY_TARGET not supported on this system 

Linux作業系統,oracle 11.2.0.4 啟動例項時出現如下錯誤:

SQL> startup nomount pfile=/u03/app/oracle/11.2.0/db/dbs/initcssb.ora
ORA-00845: MEMORY_TARGET not supported on this system

檢視錯誤幫助資訊

[oracle11@oracle11g dbs]$ oerr ora 845
00845, 00000, "MEMORY_TARGET not supported on this system"
// *Cause: The MEMORY_TARGET parameter was not supported on this operating system or /dev/shm was not sized correctly on Linux.
// *Action: Refer to documentation for a list of supported operating systems. Or, size /dev/shm to be at least the SGA_MAX_SIZE on each Oracle instance running on the system.

錯誤原因是這個作業系統不支援MEMORY_TARGET引數或/dev/shm在Linux上的大小不正確造成的,這是該作業系統上的第二個例項,第一個例項設定了MEMORY_TARGET引數,所以並不是不支援這個引數,原因就只有/dev/shm大小不正確了,解決方法是要將/dev/shm的最小值設定為作業系統上執行例項SGA_MAX_SIZE所設定的大小。/dev/shm/是linux下一個目錄,/dev/shm目錄不在磁碟上,而是在記憶體裡,因此使用linux /dev/shm/的效率非常高,直接寫進記憶體。
tmpfs有以下特點:
1.tmpfs 是一個檔案系統,而不是塊裝置;您只是安裝它,它就可以使用了。
2.動態檔案系統的大小。
3.tmpfs 的另一個主要的好處是它閃電般的速度。因為典型的 tmpfs 檔案系統會完全駐留在 RAM 中,讀寫幾乎可以是瞬間的。
4.tmpfs 資料在重新啟動之後不會保留,因為虛擬記憶體本質上就是易失的。所以有必要做一些指令碼做諸如載入、繫結的操作。

linux下/dev/shm的容量預設最大為記憶體的一半大小,使用df -h命令可以看到。但它並不會真正的佔用這塊記憶體,如果/dev/shm/下沒有任何檔案,它佔用的記憶體實際上就是0位元組;如果它最大為1G,裡頭放有100M檔案,那剩餘的900M仍然可為其它應用程式所使用,但它所佔用的100M記憶體,是絕不會被系統回收重新劃分的。

linux /dev/shm容量(大小)是可以調整,在有些情況下(如oracle資料庫)預設的最大一半記憶體不夠用,並且預設的inode數量很低一般都要調高些,這時可以用mount命令來管理它。
mount -o size=1500M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm
在2G的機器上,將最大容量調到1.5G,並且inode數量調到1000000,這意味著大致可存入最多一百萬個小檔案通過/etc/fstab檔案來修改/dev/shm的容量(增加size選項即可),修改後,重新掛載即可。

這裡該例項的SGA_MAX_SIZE為1G,下面的命令檢視/dev/shm的大小。

[root@oracle11g ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              23G   20G  1.6G  93% /
/dev/sdb1             9.9G  5.8G  3.6G  62% /u02
tmpfs                 2G    1.3M  0.7G  65% /dev/shm

從上面結果可以看到/dev/shm可用大小隻有0.7G,執行下面的命令來進行修改。

[root@oracle11g ~]# vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
/dev/sdb1               /u02                    ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults,size=4G        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda2         swap                    swap    defaults        0 0

"/etc/fstab" 7L, 540C written

解除安裝/dev/shm,但/dev/shm正被訪問

[root@oracle11g ~]#  umount /dev/shm
umount: /dev/shm: device is busy
umount: /dev/shm: device is busy

用fuser處理,fuser命令,-k:kill processes accessing the named file(殺死所有正在訪問指定檔案的程式),-m 表示指定檔案所在的檔案系統或者塊裝置(處於 mount 狀態)。所有訪問該檔案系統的程式都被列出。

[root@oracle11g ~]# fuser -km /dev/shm
/dev/shm:             3152m  3154m  3156m  3160m  3162m  3164m  3166m  3168m  3170m  3172m  3174m  3176m  3178m  3180m  3182m  3184m  3186m  3193m  3195m  3197m  3199m  3201m  3236m  3248m  3250m  3256m  3292m  4366m
[root@oracle11g ~]#  umount /dev/shm
[root@oracle11g ~]# mount /dev/shm
[root@oracle11g ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              23G   20G  1.6G  93% /
/dev/sdb1             9.9G  5.8G  3.6G  62% /u02
tmpfs                 4.0G     0  4.0G   0% /dev/shm

再重新啟動例項
SQL> startup nomount pfile=/u03/app/oracle/11.2.0/db/dbs/initcssb.ora
ORACLE instance started.

Total System Global Area 1334786560 bytes
Fixed Size 1364480 bytes
Variable Size 171970048 bytes
Database Buffers 1155189248 bytes
Redo Buffers 6262784 bytes

小結:Oracle 11g的AMM記憶體管理模式就是使用/dev/shm,所以有時候修改MEMORY_TARGET或者MEMORY_MAX_TARGET會出現ORA-00845的錯誤,在安裝配置例項記憶體時為了避免出現這個故障可以對Linux系統中的/dev/shm進行調整,讓其可用大小至少等於例項的sga_max_size。



  Oracle 11g引入了MEMORY_TARGET引數,用於控制oracle對於系統記憶體的使用,首次將SGA和PGA整合在一起實現自動管理,一旦設定了Memory_target 引數,oracle就會根據需要自動調整SGA和PGA以合理分配及使用記憶體。如果Memory_target設定不當,就容易引發ORA-00845錯誤。原因是Memory_target和/dev/shm (即tmpfs)有緊密聯絡。下面就來研究下/dev/shm究竟是什麼,他的作用是什麼,如何修改以及他的應用場景

 

一、/dev/shm是什麼

       /dev/shm是linux非常有用的一個目錄,它就是所謂的tmpfs,也可以稱之為臨時檔案系統(不是塊裝置),類似oracle中的臨時表空間一樣,用於加速和優化系統。該目錄並沒有放在磁碟上,而上在記憶體當中。因此在linux下,不用大費周折的去建ramdisk,直接使用/dev/shm就可以達到很好的效果。

       Tmpfs和ramdisk(虛擬磁碟)。Tmpfs可以使用RAM,也可以使用交換分割槽來進行儲存。傳統的ramdisk(虛擬磁碟)是個塊裝置,並且需要mkfs之類的命令之後才可以真正的使用它。Tmpfs是一個檔案系統,不是塊裝置,系統預設啟動就會載入/dev/shm,只要安裝它就可以使用了。

       Tmpfs優勢。

1.    動態檔案系統的大小

2.    讀寫速度快。典型的tmpfs檔案系統會完全駐留在RAM中,讀寫幾乎是瞬間完成。

3.    Tmpfs中的資料在重新啟動之後不會保留,因為虛擬記憶體本質上是易失的,所以有必要做些指令碼做諸如載入、繫結的操作。

 

注意

在oracle資料庫啟動後,在/dev/shm目錄下會產生大量ORA檔案,一定不要試圖去刪除這些檔案,刪除之後,oracle資料庫會宕掉。

 

 

、/dev/shm如何修改大小

 

       關於/dev/shm容量的問題,在linux下,預設/dev/shm為實際實體記憶體的1/2,使用df –h命令檢視。實際上它不會真正的佔用這塊記憶體。如果/dev/shm下沒有任何檔案,它實際佔用的記憶體就是0位元組;如果它最大為1G,裡面放有100M的檔案,那麼剩餘的900M任然可以被其他應用程式所使用,但是已經佔用的這100M記憶體空間是不會被系統回收重新劃分的。

       臨時調整tmpfs大小,重啟後失效

預設的最大一半記憶體在某些場合可能不夠用,並且預設的額inode數量很低,一般都要調高些,可以用下面的命令來實現

#mount–o size=1500m –o nr_inodes=1000000 –o noatime,nodiratime –o remount /dev/shm

在2G的機器上,/dev/shm最大尺寸調整到1.5G,並且inode數量調整到1000000,這意味著大致可存入100萬個小檔案

       永久修改tmpfs大小,修改/etc/fstab檔案

tmpfs /dev/shm tmpfsdefaults,size=1500M 0 0

修改之後remount

#mount –o remount  /dev/shm

注意:

這裡一定要注意,修改的size一定要是整數,否則在remount時候會遇到如下問題

#mount –o remount /dev/shm

mount: wrong fs type,bad option, bad superblockon tmpfs,

 missingcodepage or other error

 In somecases useful info is found in syslog – try

 dmesg |tail  or so

# dmesg | tail

Bluetooth: L2CAP socket layerinitialized

Bluetooth: RFCOMM socketlayer initialized

Bluetooth: RFCOMM TTY layerinitialized

Bluetooth: RFCOMM ver 1.8

Bluetooth: HIDP (HumanInterface Emulation) ver 1.1

mtrr: your processor doesn'tsupport write-combining

mtrr: your processor doesn'tsupport write-combining

tmpfs: Bad value '1.5G' formount option 'size'

tmpfs: Bad value '1.5G' for mount option 'size'

tmpfs: Bad value '0.5G' for mount option 'size'

三、/dev/shm應用

首先在/dev/shm建個tmp資料夾,然後與實際/tmp繫結,把/dev/shm繫結到/tmp目錄上
#mkdir /dev/shm/tmp
  #chmod 777 /dev/shm/tmp
  #mount –bind /dev/shm/tmp/tmp(–bind )
  在使用mount –bind olderdirnewerdir命令來掛載一個目錄到另一個目錄後,newerdir的許可權和所有者等所有資訊會發生變化。掛載後的目錄繼承了被掛載目錄的所有屬性,除了名稱。Oracle 11g的amm記憶體管理模式就是使用/dev/shm,所以有時候修改MEMORY_TARGET或者MEMORY_MAX_TARGET會出現ORA-00845的錯誤

 

四、tmpfs文件

 

Tmpfsis a file system which keeps all files in virtual memory.

Everythingin tmpfs is temporary in the sense that no files will be
created on your hard drive. If you unmount a tmpfs instance,
everything stored therein is lost.

tmpfsputs everything into the kernel internal caches and grows and
shrinks to accommodate the files it contains and is able to swap
unneeded pages out to swap space. It has maximum size limits which can
be adjusted on the fly via ‘mount -o remount …’

Ifyou compare it to ramfs (which was the template to create tmpfs)
you gain swapping and limit checking. Another similar thing is the RAM
disk (/dev/ram*), which simulates a fixed size hard disk in physical
RAM, where you have to create an ordinary filesystem on top. Ramdisks
cannot swap and you do not have the possibility to resize them.

Sincetmpfs lives completely in the page cache and on swap, all tmpfs
pages currently in memory will show up as cached. It will not show up
as shared or something like that. Further on you can check the actual
RAM+swap use of a tmpfs instance with df(1) and du(1).

tmpfshas the following uses:

1)There is always a kernel internal mount which you will not see at
all. This is used for shared anonymous mappings and SYSV shared
memory.

Thismount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
set, the user visible part of tmpfs is not build. But the internal
mechanisms are always present.

2)glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
POSIX shared memory (shm_open, shm_unlink). Adding the following
line to /etc/fstab should take care of this:

tmpfs/dev/shm tmpfs defaults 0 0

Rememberto create the directory that you intend to mount tmpfs on
if necessary (/dev/shm is automagically created if you use devfs).

Thismount is _not_ needed for SYSV shared memory. The internal
mount is used for that. (In the 2.3 kernel versions it was
necessary to mount the predecessor of tmpfs (shm fs) to use SYSV
shared memory)

3)Some people (including me) find it very convenient to mount it
e.g. on /tmp and /var/tmp and have a big swap partition. But be
aware: loop mounts of tmpfs files do not work due to the internal
design. So mkinitrd shipped by most distributions will fail with a
tmpfs /tmp.

4)And probably a lot more I do not know about

tmpfshas a couple of mount options:

size:The limit of allocated bytes for this tmpfs instance. The
default is half of your physical RAM without swap. If you
oversize your tmpfs instances the machine will deadlock
since the OOM handler will not be able to free that memory.
nr_blocks: The same as size, but in blocks of PAGECACHE_SIZE.
nr_inodes: The maximum number of inodes for this instance. The default
is half of the number of your physical RAM pages.

Theseparameters accept a suffix k, m or g for kilo, mega and giga and
can be changed on remount.

Tospecify the initial root directory you can use the following mount
options:

mode:The permissions as an octal number
uid: The user id
gid: The group id

Theseoptions do not have any effect on remount. You can change these
parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.

So‘mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs’
will give you tmpfs instance on /mytmpfs which can allocate 10GB
RAM/SWAP in 10240 inodes and it is only accessible by root.

TODOs:

1)give the size option a percent semantic: If you give a mount option
size=50% the tmpfs instance should be able to grow to 50 percent of
RAM + swap. So the instance should adapt automatically if you add
or remove swap space.
2) loop mounts: This is difficult since loop.c relies on the readpage
operation. This operation gets a page from the caller to be filled
with the content of the file at that position. But tmpfs always has
the page and thus cannot copy the content to the given page. So it
cannot provide this operation. The VM had to be changed seriously
to achieve this.
3) Show the number of tmpfs RAM pages. (As shared?)

Author:
Christoph Rohland , 1.12.01

 

 五、Doc ID 1399209.1

Starting with Oracle Database 11g, the Automatic MemoryManagement feature requires more shared memory (/dev/shm) and file descriptors.The size of the shared memory must be at least the greater of theMEMORY_MAX_TARGET and MEMORY_TARGET parameters for each Oracle instance on thecomputer. If the MEMORY_MAX_TARGET parameter or the MEMORY_TARGET parameter isset to a nonzero value, and an incorrect size is assigned to the shared memory,it results in an ORA-00845 error at startup. 
On Linux systems, if the operating system /dev/shm mount size is too small forthe Oracle system global area (SGA) and program global area (PGA), then youencounter the following error:

The cause of this error is an insufficient /dev/shm allocation.The total memory size of the SGA and PGA, which sets the initializationparameter MEMORY_TARGET or MEMORY_MAX_TARGET, cannot be greater than the sharedmemory file system (/dev/shm) on your operating system.

 

整理自網路

 



使用redhat系列的作業系統,可以發現系統預設掛載了/dev/shm,掛載型別為tmpfs。

在glibc2.2以上的版本,使用/dev/shm 作為POSIX 共享記憶體 (shm_open, shm_unlink),在fstab上可以看到

tmpfs /dev/shm tmpfs defaults 0 0

這裡要說下tmpfs。

tmpfs從名字看就知道是臨時檔案系統,所以寫入到tmpfs型別的分割槽下的檔案都不會寫入硬碟,只是儲存在硬碟裡,tmpfs在掛載時如果沒有指定size預設使用實體記憶體的一半作為它的值。相對於ramfs,tmpfs有它一系列的優勢,首先它能被用於交換,更重要的是掛載一個tmpfs型別的分割槽並不實際佔用實體記憶體(當然往裡寫了就開始佔記憶體了,即寫1M的檔案進去,就佔了1M)。而ramfs的話在初始化的時候就限制了,必須分配掉相應的記憶體作為物理磁碟,事實上就算你還沒用記憶體就已經少掉了。

利用tmpfs,同樣的,我可以手動建立個目錄並掛載

mount -t proc none /mnt/1

這樣,/mnt/1 也是tmpfs型別。使用df -h可以看到多了個分割槽,並且大小也是記憶體的一半。之後就隨便怎麼用啦~

最後當umount掉分割槽後,所有該分割槽的檔案就自動消失了,記憶體被釋放。

ORACLE 資料庫從11g 版本開始,引入了一個自動記憶體管理(Automatic Memory Management)特性,該特性需要更多的共享記憶體(/dev/shm),因此如果決定應用該特性的話, 必須要確保共享記憶體大於ORACLE 中初始化引數MEMORY_MAX_TARGET 和MEMORY_TARGET(特別提示,這兩個引數即自動記憶體管理特性對應的初始化引數)的值。
如果在初始化引數中設定了MEMORY_MAX_TARGET 和MEMORY_TARGET 兩引數為非0 值,並且不符合系統共享記憶體,則ORACLE 資料庫啟動時,就會觸發ORA-00845:MEMORY_TARGET not supported on this system 錯誤。

ORACLE官方文件中的原話為:
Automatic Memory Management
Starting with Oracle Database 11g, the Automatic Memory Management feature requires more shared memory (/dev/shm)and file descriptors. The size of the shared memory should be at least the greater of MEMORY_MAX_TARGET and MEMORY_TARGET
for each Oracle instance on the computer. If MEMORY_MAX_TARGET or MEMORY_TARGET is set to a non zero value, and an incorrect size is assigned to the shared memory, it will result in an ORA-00845 error at startup. On Linux systems, if the operating system /dev/shm mount size is too small for the Oracle system global area (SGA) and program global area (PGA), even then it will result in an ORA-00845 error.
The number of file descriptors for each Oracle instance should be at least 512*PROCESSES. Also, the limit of descriptors for each process should be at least 512.
If file descriptors are not sized correctly, you will notice ORA-27123 from various Oracle processes and potentially Linux Error EMFILE (Too many open files) errors in non-Oracle processes.
To determine the amount of shared memory available, enter the following command:

# df -h /dev/shm/




 

Linux umount 報 device is busy 的處理方法



 

       今天在IDC 輻射了半天,又弄了套DG。 在Linux 掛盤這塊也小學了兩招。

 

.  umout 行動硬碟

       開始用sftp 將安裝檔案copy到伺服器的時候,速度太慢了,500k/s。幾個G的東西,copy 這些就要半個多小時,扛不住,拿行動硬碟來copy了。結果行動硬碟的格式不對。 是NTFS 格式,Linux 識別不了。 只能格式化成FAT32的。 而GG win7 系統又不具備格式化成FAT32的功能。 有點小變態。讓同事在XP 下幫我格式化了。

 

       安裝檔案copy到伺服器後,同事直接將行動硬碟從伺服器上拔下來了。 導致的結果是,用df 命令檢視,掛載的行動硬碟還存在。

 

[root@qs-wg-db1 ~]# df -lh

Filesystem            Size  Used Avail Use% Mounted on

/dev/sdb3             125G  3.3G  115G   3% /

/dev/sdb1              99M   12M   82M  13% /boot

tmpfs                 3.9G     0  3.9G   0% /dev/shm

/dev/sda1             275G   72G  189G  28% /u01

/dev/sdc1              10G  2.0G  8.1G  20% /datatmp

 

就是這個/dev/sdc1

 

這時使用umount 命令,會提示裝置忙,無法掛載。

 

處理方法:

[root@qs-wg-db1 ~]# fuser -km /datatmp

[root@qs-wg-db1 ~]# df -lh

Filesystem            Size  Used Avail Use% Mounted on

/dev/sdb3             125G  3.3G  115G   3% /

/dev/sdb1              99M   12M   82M  13% /boot

tmpfs                 3.9G     0  3.9G   0% /dev/shm

/dev/sda1             275G   72G  189G  28% /u01

/dev/sdc1              10G  2.0G  8.1G  20% /datatmp

[root@qs-wg-db1 ~]# umount /datatmp

[root@qs-wg-db1 ~]# df -lh

Filesystem            Size  Used Avail Use% Mounted on

/dev/sdb3             125G  3.3G  115G   3% /

/dev/sdb1              99M   12M   82M  13% /boot

tmpfs                 3.9G     0  3.9G   0% /dev/shm

/dev/sda1             275G   72G  189G  28% /u01

 

成功umount了。

 

.  umount 光碟機

       安裝DB 之前,檢查了一下相關包,少了3個。 從系統安裝盤上找了包,安裝了一下。 當時是直接將/dev/cdrom mount 到了/mnt目錄。 也是圖個方便。 結果收工時去拿盤,光碟機彈不出來。 同事讓我把cdrom umout掉。 同樣的提示,裝置忙。

 

處理方法:

[root@qs-wg-db1 ~]#fuser –km /dev/cdrom

[root@qs-wg-db1 ~]#eject  -- 彈出光碟機

 

 

在網上搜了一下,正確掛載CD-ROM的方法應該如下:

 

# mkdir cdrom
# mount /dev/cdrom /mnt/cdrom
或者 

# mount /dev/cdrom /media/cdrom

 

直接掛載在/mnt,/media等系統目錄下,在umount時會出現出錯資訊“umount: /mnt/cdrom: device is busy”的情況。

 

如果一個檔案系統處於“busy”狀態的時候,不能解除安裝該檔案系統。如下情況將導致檔案系統處於“busy”狀態:

       1) 檔案系統上面有開啟的檔案

       2) 某個程式的工作目錄在此檔案系統上

       3) 檔案系統上面的快取檔案正在被使用

 

.  fuser 命令

       前面2umout 都使用了這個fuser 命令。 man了一下這個命令。 內容如下:

 

[root@qs-wg-db1 ~]# man fuser

FUSER(1)       User Commands                        FUSER(1)

 

NAME

       fuser - identify processes using files or sockets

 

SYNOPSIS

       fuser [-a|-s|-c] [-4|-6] [-n  space ] [-k [-i] [-signal ] ] [-muvf] name

       fuser -l

       fuser -V

 

DESCRIPTION

       fuser displays the PIDs of processes using the specified files or file systems.  In the default display mode, each file name is followed by a letter denoting the  type

       of access:

              c      current directory.

              e      executable being run.

              f      open file. f is omitted in default display mode.

              F      open file for writing. F is omitted in default display mode.

              r      root directory.

              m      mmap'ed file or shared library.

 

       fuser  returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access  has  been  found,  fuser  returns zero.

       In  order  to  look  up processes using TCP and UDP sockets, the corresponding name space has to be selected with the -n option. By default fuser  will  look  in  both IPv6  and IPv4 sockets. To change the default, behavior, use the -4 and -6 options. The socket(s) can be specified by  the  local  and  remote  port,  and  the  remote address.  All  fields  are optional, but commas in front of missing fields must be present:

       [lcl_port][,[rmt_host][,[rmt_port]]]

       Either symbolic or numeric values can be used for IP addresses and port numbers.

      

fuser outputs only the PIDs to stdout, everything else is sent to stderr.

 

OPTIONS

       -a     Show all files specified on the command line. By default,  only  files  that are accessed by at least one process are shown.

       -c     Same as -m option, used for POSIX compatibility.

       -f     Silently ignored, used for POSIX compatibility.

       -k     Kill  processes  accessing the file. Unless changed with -signal, SIGKILL is sent. An fuser process never kills itself, but may  kill  other  fuser  processes.  The  effective user ID of the process executing fuser is set to its real user ID before attempting to kill.

       -i     Ask the user for confirmation before  killing  a  process.  This  option  is silently ignored if -k is not present too.

       -l     List all known signal names.

       -m    name  specifies  a  file  on a mounted file system or a block device that is mounted. All processes accessing files on that file system are listed.  If adirectory  file  is  specified, it is automatically changed to name/. to use any file system that might be mounted on that directory.

 

       -n space Select a different name  space.  The  name  spaces  file  (file  names,  the default),  udp  (local UDP ports), and tcp (local TCP ports) are supported. For ports, either the port number or the symbolic name can be specified.  If there  is no ambiguity, the shortcut notation name/Ispace (e.g. 80/tcp ) can be used.

       -s     Silent operation. -u and -v are ignored in this mode.  -a must not  be  used with -s.

       -signal Use  the specified signal instead of SIGKILL when killing processes. Signals can be specified either by name (e.g. -HUP) or by  number  (e.g.  -1).  This option is silently ignored if the -k option is not used.

       -u     Append the user name of the process owner to each PID.

       -v     Verbose  mode.  Processes are shown in a ps-like style. The fields PID, USER and COMMAND are similar to ps. ACCESS shows how  the  process  accesses  the file.  If  the access is by the kernel (e.g. in the case of a mount point, awap file, etc.), kernel is shown instead of the PID.

       -V     Display version information.

       -4     Search only for IPv4 sockets. This option must  not  be  used  with  the  -6 option and only has an effect with the tcp and udp namespaces.

       -6     Search  only  for  IPv6  sockets.  This  option must not be used with the -4 option and only has an effect with the tcp and udp namespaces.

       -      Reset all options and set the signal back to SIGKILL.

FILES

       /proc     location of the proc file system

 

fuser 命令顯示訪問某個檔案的程式的PID. 其中-k  -m 引數上面紅色部分有說明。-k kill 訪問這個檔案的程式。 沒有程式訪問,就可以成功umount.





About Me

...............................................................................................................................

● 本文整理自網路

● 本文在itpub(http://blog.itpub.net/26736162)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● QQ群:230161599     微信群:私聊

● 聯絡我請加QQ好友(646634621),註明新增緣由

● 於 2017-07-01 09:00 ~ 2017-07-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

...............................................................................................................................

拿起手機使用微信客戶端掃描下邊的左邊圖片來關注小麥苗的微信公眾號:xiaomaimiaolhr,掃描右邊的二維碼加入小麥苗的QQ群,學習最實用的資料庫技術。

【OS】Linux下/dev/shm的作用及ORA-00845錯誤的處理
DBA筆試面試講解
歡迎與我聯絡

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2142633/,如需轉載,請註明出處,否則將追究法律責任。

相關文章