Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Linux file system data file deletion problem space is not freed     - How to enhance the Nagios server security (Linux)

- Findbugs installation documentation (Linux)

- Docker startups use continuous integration deployment (Server)

- Iptables principle (Linux)

- Import and export myloader accelerate mydumper (Database)

- Linux can modify the maximum number of open files (Linux)

- Linux file system management partition, format, mount - label mount (Linux)

- Linux system find command Detailed (Linux)

- Linux shell script debugging (Linux)

- How to manage KVM virtual environments with command-line tools in Linux (Server)

- Ubuntu system grub repair method (Linux)

- The Linux role of each directory contents (Linux)

- Oracle 11g RMAN virtual private directory (Database)

- Use ldap implement Windows Remote Desktop Ubuntu Linux (Linux)

- CentOS6 5 source compiler installation Hadoop2.5.1 (Server)

- Use eCryptFS encrypt files and directories on Linux (Linux)

- Linux basic introductory tutorial ---- Software Installation under Linux (Linux)

- CentOS 6.6 install JDK7 (Linux)

- CentOS 6.4 Telecom ADSL dial-up network configuration (Linux)

- GAMIT10.5 install and update failed Solution (Linux)

 
         
  Linux file system data file deletion problem space is not freed
     
  Add Date : 2018-11-21      
         
         
         
  First, delete the file system space data file does not release the problem is not present in the Linux platform, all platforms are likely to have this problem. Here are just doing some tests on the Linux platform, similar to other platforms; secondly only the data files stored in the file system will have such problems, if the database is stored in ASM will not have similar problems, the purpose of this article is summarize the relevant issues, familiar tools and methods, which is more important.

Writing this article is because customers have a database, AIX 6.1, the data files are stored in the file system, after using the DROP TABLESPACE UNDO INCLUDING CONTENTS AND DATAFILES deleted UNDO table space, file system space has not been released. How to solve the problem it would be to write the original intention of this article.

Space is not released, we may see confirmed by df command, when we used to scan du catalog size you may find df and du command to see two space usage is different and may vary widely, following this MOS article explains why:

'Du' and 'df' tools report different space utilization (Document ID 457444.1)


In this Document
 
Symptoms
Cause
Solution
 
Applies to:
Linux OS - Version Oracle Linux 4.4 and later
Linux x86-64
Linux x86
Linux Kernel - Version: 4.4 to 5.3
 
 
Symptoms
The 'du' (/ usr / bin / du) and 'df' (/ bin / df) command output displays conflicting space utilisation values, for example:
# Df -k /
Filesystem 1k-blocks Used Available Use% Mounted on
/ Dev / sda6 9288792 8672768 144120 99% /
 
# Du -xsh /
2.1G /
 
In the example above, 'df' reports 8.6 Gb to have been used on the root (/) filesystem, whereas 'du' reports only 2.1 Gb to have been used.
 
Cause
The 'df' command reports how many disk blocks are used, whilst 'du' traverses the filesystem and reports the actual number of blocks used (directory by directory), including any relating to files in use by processes.
 
In most cases, space utilisation values ​​returned from 'df' and 'du' will be consistent. However, the potential exists for a running process to delete a large file, say. In this instance, according to 'du', the large file no longer exists, so the blocks associated with the deleted file are not reported. With the process still running, and with an open file descriptor still held against the deleted file, 'df' continues to track and report all disk blocks used, including those associated with the deleted (phantom) file. In this situation, the disk space associated with the deleted file will only be relinquished back to the system when the process completely releases the deleted file's descriptor or the process terminates (either gracefully or killed).
Solution
The solution is to identify and stop (or kill) the process that continues to hold a file descriptor open for the deleted file To do so, run the lsof command. (/ Usr / sbin / lsof | grep deleted) as root to identify the holding process, for example:
 
# Lsof | grep deleted

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
cannaserv 3825 canna 0u CHR 136,0 2 / dev / pts / 0 (deleted)
vmware 4295 root 6u REG 253,0 6770 13074503 /tmp/vmware-root/ui-4295.log (deleted)
vmware-re 4316 root 6u REG 253,0 6770 13074503 /tmp/vmware-root/ui-4295.log (deleted)
vmnet-nat 4448 root 0u CHR 136,0 2 / dev / pts / 0 (deleted)
vmware-se 4454 root 0u CHR 136,0 2 / dev / pts / 0 (deleted)
gdm-binar 4506 root 0u CHR 136,0 2 / dev / pts / 0 (deleted)
gconfd-2 5392 root 12wW REG 253,0 609 13090818 / tmp / gconfd-root / lock / 0t1188207163ut519551u0p5392r346479926k3219784492 (deleted)
vmware-vm 5822 root 57u REG 253,0 6520832 13074477 / tmp / vmware-root / ram0 (deleted)
vmware-vm 16487 root 57u REG 253,0 11153408 13074520 / tmp / vmware-root / ram0 (deleted)
kdeinit 17991 root 17u REG 253,0 26712 13074524 /tmp/kde-root/khtmlcacheM7jXYb.tmp (deleted)
kdeinit 17991 root 18u REG 253,0 5631 13074501 /tmp/kde-root/khtmlcacheZlJmda.tmp (deleted)
kdeinit 17991 root 21u REG 253,0 44718 13074514 /tmp/kde-root/khtmlcacheH5m4lc.tmp (deleted)
 
In the example above, the 7th column in the output denotes the size of deleted files (in bytes). The 9th column denotes which file remains held open. The 1st and second columns denotes the process and pid that still holds the open file descriptor.

    The reason df and du command to see the use of space there will be differences, because the du not count deleted files, df will count file has been deleted, but the file is still held by the process, and only processes such as the release of the document, df did not count. By lsof | grep deleted command to find the deleted files of the case are still being held by the process.

    Through the above article, we learned that deleting a large file space is not released in the process because there is still holding it, find the process if you need to use the command lsof and fuser command, familiar with these two commands in the file system very important.

> Lsof (list open files) are listed in the current system is a tool to open the file.
> Fuser is used to identify a file or socket process information.

   fuser is that we usually find a common process tools, but it does not list details of the process information, just one more process ID can not be very good filtering, in this scene more appropriate lsof tool.

In addition, we all know, in the Linux platform file system, even if a file is deleted, but if there is any natural process of holding it, the files can be restored, which is why all the database data files are deleted, in examples of reasons for the case of no downtime can completely recover the data file, the following article will discuss this MOS in this case how to recover data files:

How To Recover Deleted Files on ext3 / ext4 Filesystem (Document ID 2056343.1)
 
 
 
 
In this Document
 
Goal
Solution
References
 
Applies to:
Linux OS - Version Oracle Linux 5.0 and later
Linux x86-64
Linux x86
Goal
How to recover deleted file on ext3 / ext4 filesystem, Which still has file descriptor opened.
Solution
A file in Linux is a pointer to an inode which contains the file data (permissions, owner and where its actual content resides on the disk).
Deleting the file removes the link, but not the inode itself.
If any other process has this file open then inode is not released for writing until the process releases it.
So if a process still has the file open, the data are there somewhere, even though the directory listing shows no files.
# Ll
total 4
-rw-r - r-- 1 root root 27 Sep 16 05:19 test
# Rm test
# Lsof / opt / test / test
COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
less 21353 root 4r ​​REG 252,2 27 260360 / opt / test / test (deleted) <<<<<<<<<<<<<

Understanding output of "lsof" command:
COMMAND: Command using the file.
PID: PID of the file
USER: Owner of the file
FD: File descriptor Different flags of File descriptor are as below.:
#: The number in front of flag (s) is the file descriptor number of used by the process to associated with the file
u: File open with Read and Write permission
r: File open with Read permission
w: File open with Write permission
W: File open with Write permission and with Write Lock on entire file
mem: Memory mapped file, usually for share library
TYPE:. File type Different flags of File type are as below:
REG - Regular file
DIR - Directory
DEVICE: major, minor number of the device where file resides.
SIZE / OFF: File size
NODE: inode number
NAME: File name

Now we know that process 21353 still has the file open, and the file descriptor is 4.
Now we can look into / proc and there will be a reference to the inode, from which the deleted file can be copied.
Following steps will help to recover the deleted files:
# Ls -l / proc / 21353 / fd / 4
  lr-x ------ 1 root root 64 Sep 16 05:28 / proc / 21353 / fd / 4 -> / opt / test / test (deleted)
# Cp / proc / 21353 / fd / 4 /opt/test/test.bkp
Now verify the content of the restored file.
Note: Do not use the -a flag with cp, as this will copy the (broken) symbolic link, rather than the actual file contents.

In addition, a process to find the file is held, you can see the process related to environmental information through the following methods:

Checking the environment variables of ASM pmon process: It shows ORACLE_HOME is set to /oracle_grid/product/11.2.0.3/grid/ (with 'slash' at the end)

# Ps -ef | grep pmon
oracle 27232 1 0 May30? 00:07:05 asm_pmon_ + ASM1

# Cat / proc / 27232 / environ
__CLSAGFW_TYPE_NAME = Ora.asm.typeORA_CRS_HOME = / oracle_grid / product / 11.2.0.3 / grid / HOSTNAME = aude3od015naboi.basdev.aurdev.national.com.auTERM = xtermSHELL = / bin / bash__CR ......

Summary: For such problems, we must first understand why df and du have calculated the difference in space, followed by two to be familiar with lsof and fuser command to find the process ID of the file continue to hold, through the process ID in / restore files in proc directory, view the process of environmental information, and even to kill the process to free up space.


Finally, a simple example to the end of this article:

1. First make sure lsof tool has been installed into the operating system.
[Root @ rac01 Server] # rpm -ivh lsof-4.78-6.x86_64.rpm
Preparing ... ########################################### [100% ]
   1: lsof ########################################### [100%]
[Root @ rac01 Server] # which lsof
/ Usr / sbin / lsof

2. In one of the sessions by making tail command tail -f install2.log process to hold the file, delete the file in another session by rm -rf install2.log command.

3. Use lsof to perform the following operations:

[Root @ rac01 ~] # lsof | grep deleted
tail 6006 root 3r REG 8,3 29544 4587629 /root/install2.log (deleted)
[Root @ rac01 ~] # cd / proc / 6006 /
[Root @ rac01 6006] # ls
attr cmdline cwd fdinfo loginuid mounts numa_maps pagemap schedstat stat task
auxv comm environ io maps mountstats oom_adj personality sessionid statm wchan
cgroup coredump_filter exe latency mem net oom_score root smaps status
clear_refs cpuset fd limits mountinfo ns oom_score_adj sched stack syscall
[Root @ rac01 6006] # cd fd
[Root @ rac01 fd] # ll
total 0
lrwx ------ 1 root root 64 Dec 3 19:07 0 -> / dev / pts / 0
lrwx ------ 1 root root 64 Dec 3 19:07 1 -> / dev / pts / 0
lrwx ------ 1 root root 64 Dec 3 19:07 2 -> / dev / pts / 0
lr-x ------ 1 root root 64 Dec 3 19:07 3 -> /root/install2.log (deleted)
[Root @ rac01 fd] # cd ..
[Root @ rac01 6006] # cat environ

HOSTNAME = rac01TERM = vt100SHELL = / bin / bashHISTSIZE = 1000SSH_CLIENT = 172.168.4.123 56823 22OLDPWD = / mnt / ServerSSH_TTY = / dev / pts / 0USER = rootLS_COLORS = no = 00: fi = 00: di = 01; 34: ln = 01 ; 36: pi = 40; 33: so = 01; 35: bd = 40; 33; 01: cd = 40; 33; 01: or = 01; 05; 37; 41: mi = 01; 05; 37; 41 : ex = 01; 32: * cmd = 01; 32:.. * exe = 01; 32:. * com = 01; 32: * btm = 01; 32:.. * bat = 01; 32: * sh. = 01; 32:. * csh = 01; 32:. * tar = 01; 31:. * tgz = 01; 31:. * arj = 01; 31:. * taz = 01; 31: * lzh = 01. ; 31:. * zip = 01; 31:. * z = 01; 31:. * Z = 01; 31:. * gz = 01; 31: * bz2 = 01; 31:.. * bz = 01; 31 .: * tz = 01; 31:. * rpm = 01; 31:. * cpio = 01; 31:. * jpg = 01; 35:. * gif = 01; 35:. * bmp = 01; 35: * .xbm = 01; 35:. * xpm = 01; 35:. * png = 01; 35:. * tif = 01; 35: mAIL = / var / spool / mail / rootPATH = / usr / local / sbin: / usr / local / bin: / sbin: / bin: / usr / sbin: / usr / bin: /root/binINPUTRC=/etc/inputrcPWD=/rootLANG=en_US.UTF-8SSH_ASKPASS=/usr/libexec/openssh/gnome- ssh-askpassSHLVL = 1HOME = / rootLOGNAME = rootSSH_CONNECTION = 172.168.4.123 56823 172.168.4.200 22LESSOPEN = | /usr/bin/lesspipe.sh% sG_BROKEN_FILENAMES = 1 _ = / usr / bin / tail
[Root @ rac01 6006] # lsof / root / it <<<< finds the process of holding / root directory files
COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
bash 4934 root cwd DIR 8,3 4096 4587521 / root /
tail 6006 root cwd DIR 8,3 4096 4587521 / root /
[Root @ rac01 6006] # lsof -c file tail tail figure out the process of holding <<<<
COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
tail 6006 root cwd DIR 8,3 4096 4587521 / root
tail 6006 root rtd DIR 8,3 4096 2 /
tail 6006 root txt REG 8,3 37704 1448826 / usr / bin / tail
tail 6006 root mem REG 8,3 56479136 1446088 / usr / lib / locale / locale-archive
tail 6006 root mem REG 8,3 1720736 5242891 /lib64/libc-2.5.so
tail 6006 root mem REG 8,3 142488 5242884 /lib64/ld-2.5.so
tail 6006 root 0u CHR 136,0 0t0 3 / dev / pts / 0
tail 6006 root 1u CHR 136,0 0t0 3 / dev / pts / 0
tail 6006 root 2u CHR 136,0 0t0 3 / dev / pts / 0
tail 6006 root 3r REG 8,3 29544 4587629 /root/install2.log (deleted)
[Root @ rac01 6006] # lsof + d / root / <<<< display process to access the / root directory files.
COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
bash 4934 root cwd DIR 8,3 4096 4587521 / root /
tail 6006 root cwd DIR 8,3 4096 4587521 / root /
[Root @ rac01 6006] # lsof + D / root / <<<< display process to access the / root directory and subdirectories of the file.
COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
bash 4934 root cwd DIR 8,3 4096 4587521 / root /
tail 6006 root cwd DIR 8,3 4096 4587521 / root /
[Root @ rac01 6006] # lsof -d 3 | grep -v grep | grep deleted <<<< display file FD holds for the process 3 files
tail 6006 root 3r REG 8,3 29544 4587629 /root/install2.log (deleted)
[Root @ rac01 6006] # lsof -p 6006 <<<< 6006 file show the process of holding
COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
tail 6006 root cwd DIR 8,3 4096 4587521 / root
tail 6006 root rtd DIR 8,3 4096 2 /
tail 6006 root txt REG 8,3 37704 1448826 / usr / bin / tail
tail 6006 root mem REG 8,3 56479136 1446088 / usr / lib / locale / locale-archive
tail 6006 root mem REG 8,3 1720736 5242891 /lib64/libc-2.5.so
tail 6006 root mem REG 8,3 142488 5242884 /lib64/ld-2.5.so
tail 6006 root 0u CHR 136,0 0t0 3 / dev / pts / 0
tail 6006 root 1u CHR 136,0 0t0 3 / dev / pts / 0
tail 6006 root 2u CHR 136,0 0t0 3 / dev / pts / 0
tail 6006 root 3r REG 8,3 29544 4587629 /root/install2.log (deleted)
[Root @ rac01 6006] # lsof -u root | grep deleted <<<< process held by the user is displayed as the root file
tail 6006 root 3r REG 8,3 29544 4587629 /root/install2.log (deleted)
[Root @ rac01 6006] # cd / proc / 6006 / fd /
[Root @ rac01 fd] # cp 3 /root/install2.log <<<< recover deleted files install2.log
[Root @ rac01 fd] # cd / proc / 6006 / fd
[Root @ rac01 fd] # ll
total 0

lrwx ------ 1 root root 64 Dec 3 19:07 0 -> / dev / pts / 0
lrwx ------ 1 root root 64 Dec 3 19:07 1 -> / dev / pts / 0
lrwx ------ 1 root root 64 Dec 3 19:07 2 -> / dev / pts / 0
lr-x ------ 1 root root 64 Dec 3 19:07 3 -> After /root/install2.log (deleted) <<<< deleted file recovery status is not changed.
[Root @ rac01 fd] # cd / root /
[Root @ rac01 ~] # ls
anaconda-ks.cfg core.11067 core.526 core.6027 core.7965 Desktop install2.log install.log install.log.syslog

--end--
     
         
         
         
  More:      
 
- Linux unpack the tar file to a different directory (Linux)
- Linux security-related basics (Linux)
- Linux System Getting Started Learning: Join cron job in Linux (Linux)
- IOwait Linux system monitoring diagnostic tools (Linux)
- About Leetcode on Binary Tree Algorithm summary (Programming)
- Linux Telnet access Windows 7 configuration procedure (Linux)
- Snort build a secure Linux server (Linux)
- Using Linux strace command trace / debug a program commonly used options (Linux)
- PXE + Kickstart automatically install CentOS 6.5 (Linux)
- MongoDB data replication and data slices (Database)
- MySQL + Heartbeat + DRBD deployment architecture (Server)
- Android Touch message passing mechanism analysis (Programming)
- C ++ Fundamentals study notes (Programming)
- Linux performance monitoring and common commands Introduction (Linux)
- Debian (Wheezy) Install Java environment / replace OpenJDK as the SUN JDK (Linux)
- Hadoop 2.7.1 Installation and Configuration under RedHat Linux 6.5 (Server)
- How to install web crawler tool in Ubuntu 14.04 LTS: Scrapy (Linux)
- Java String and StringBuffer and StringBuilder Comments (Programming)
- Nine trick to let you speed up the old machine running Ubuntu Linux (Linux)
- Build their own recursive DNS server (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.