I have a Django app with a postgresql backend. Postgresql creates temporary files every now and then - this can be a killer if disk space is critical (as is my case).
One way to alleviate the problem is to create a symlink to some other storage location where disk space isn't a bottleneck. In my case, postgresql stores temporary files at /$PGDATA/base/pgsql_tmp
. I have a big SSD mounted at /mnt
, so I want the temp files to reside there instead. The following ought to take care of this:
ln -sTf /mnt/pgsql_tmp $PGDATA/base/pgsql_tmp
chown -R postgres /mnt/pgsql_tmp #ensuring user 'postgres' has the right perms
chmod o+x /mnt
Before I do this in production, I decided to test this out locally. I created /mnt
and /pgsql_tmp
on my desktop, and then tried ln -sTf /home/hassan/Desktop/mnt/pgsql_tmp /home/hassan/Desktop/pgsql_tmp
.
But this ends up giving me ln: ‘/home/hassan/Desktop/pgsql_tmp’: cannot overwrite directory
. Can anyone point out what I'm doing wrong? Being a neophyte, I'm really trying to wrap my head around how this works.
Your best bet is to delete ~/pgsql_tmp
, and let the ln command create it.
First note that LN doesn't link two objects; it creates a link to a target with a specific name from a place.
ln [OPTION]... [-T] TARGET LINK_NAME
When you create a link with ln
, the NAME argument should indicate an object that does not yet exist, and it will be created as the result of the command. In your case you already created it (~/pgsql_tmp
) as a directory.
Usually, You can use the -f
switch to force deletion of anything already overlaping the NAME's path, but in your case you specified -T
which means that you want to create the link as a File, not as a Directory. So when -f
goes to overwrite the object at NAME, its trying to overwrite a directory with a file.
So, you can either create the link as a directory and use -f, or you can delete the object that overlaps NAME, and then create your link. The later is the best option.
#create a test target with a file, but without an object at lnname
~/tmp$ mkdir lntarget
~/tmp$ touch lntarget/contentfile1
~/tmp$ ln -sTf lntarget lnname
~/tmp$ ls ./lnname
contentfile1
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments