All we need is an easy explanation of the problem, so here it is.
I am trying to clear the logs of an postgresql under /var/log/postgresql/ but I am getting error message as below:
/var/log/postgresql$ sudo > postgresql-11-main.log
-bash: postgresql-11-main.log: Permission denied
Below is folder files structure:
/var/log/postgresql$ ls -la
total 1097296
drwxrwxr-t 2 root postgres 4096 Apr 25 06:56 .
drwxrwxr-x 12 root syslog 4096 Apr 28 06:35 ..
-rw-r----- 1 postgres adm 1107919237 Apr 29 06:33 postgresql-11-main.log
-rw-r----- 1 postgres adm 14480619 Apr 25 06:56 postgresql-11-main.log.1
-rw-r----- 1 postgres adm 1199751 Apr 18 06:49 postgresql-11-main.log.2.gz
Also, is it okay to clear the logs of an PostgreSQL? will it harm any existing database or work flow?
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
That is a bash
problem. The redirection (>
) is not part of the command executed as root
, but as your current user.
Use this workaround:
sudo sh -c "> /var/log/postgresql/postgresql-11-main.log"
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0