1

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?

1 Answer 1

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"
2
  • thank you for the reply. Is it okay to clear the logs of an PostgreSQL? will it harm any existing database or work flow?
    – Akash M
    Commented Apr 29, 2021 at 6:51
  • It won't do any harm. Commented Apr 29, 2021 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.