Why I can't write a file in /tmp/ even when it is root:root and has "t" flag?

Solution 1:

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