I am using the postgres user to execute some special commands. For that, I am trying the following:
$ sudo su - postgres
postgres$ ls -l /tmp
drwxrwxrwt 13 root root 4096 jun 8 12:20 tmp PGPASSWORD=mypasswordhere time pg_dump --username=postgres --no-password -f /tmp/myfilehere.sql mydatabasehere
pg_dump: [archiver] could not open output file "/tmp/myfilehere.sql": Permiso denegado
Command exited with non-zero status 1
0.25user 0.06system 0:02.04elapsed 15%CPU (0avgtext+0avgdata 58064maxresident)k
0inputs+0outputs (0major+5110minor)pagefaults 0swapsQuestion: Why can't I write in /tmp with user postgres? Noticing the sticky flag is set on /tmp.
1 Answer
The sticky bit will prevent any user other than the owner of file (and owner of directory and root) to remove/rename any file inside the directory containing sticky bit. If any user does not have permission to write then he would not be able to create any file in /tmp or any other directory having sticky bit set, same goes for read and execute operations.
In your case if postgres has sufficient permission to read/write/execute files in /tmp then he can do that otherwise you need to set the appropriate permissions manually.
Example :
drwxrwxrwt 7 root root 4096 Jun 9 00:41 tmp
$ sudo chmod o-rwx /tmp
drwxrwx--T 7 root root 4096 Jun 9 00:41 tmp
$ touch /tmp/foo.txt
touch: cannot touch ‘/tmp/foo.txt’: Permission denied
$ sudo chmod o+rwx /tmp
$ touch /tmp/foo.txt
$ ls -l /tmp/
-rw-rw-r-- 1 user user 0 Jun 9 00:50 foo.txt 1