简体   繁体   中英

Replacing Open Files With Symlinks In Linux?

Right now, I have a file with data and a database living on the same disk. A long-running, atomic insert might end up filling up the disk before it can commit. Is there anyway that I can replace the data file with a symbolic link to save a few hundred gigabytes, even though the database presumably has the current file open? In case there is not such a filesystem-level solution, and a "re-open data, and keep going from checkpoint" action is needed, I'm using postgres 9.5 and the datafile is generated by pg_dump.

My main question and curiosity is about the possibility of replacing files with links without interrupting programs that have them open, but I'm motivated by a situation here. Any knowledge about how to associate more disk space with the directory the database lives on without interrupting currently running programs would also come in handy.

There is no way to “replace” a file that a process currently has open.

But you can extend the file system on which the file is residing on the fly, provided you use LVM, there is free space in the volume group containing the file system and the file system type allows resizing.

Here is a solution for the file system ext2 and its successors:

  • find the logical volume where your file resides

     # df /path/to/large/file Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/datalv 991512 991500 12 100% /path/to 
  • Find the volume group where your file resides

     # lvdisplay -c /dev/mapper/datalv | cut -d: -f2 datavg 
  • Find the physical extent size and how many are free

     # vgdisplay -c datavg | cut -d: -f13,16 4096:476 

    Free space is 476 times 4 MB or 1904 MB.

  • Extend the logical volume by 1 GB

     # lvextend -L +1G /dev/mapper/datalv 
  • Resize the ext n file system online

     # resize2fs /dev/mapper/datalv 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM