www.gsx.com | log in | register

Last update: . Author: Alan Carson .

How to Prevent PostgreSQL Logs from Filling Up Your C: Drive

PostgreSQL logs can become very large and may need some routine maintenance to prevent them from filling up C:\ drive capacity. Logs are invaluable when diagnosing problems. However, the PostgreSQL log output can become extremely large (5 GB x day), especially at higher debug levels.

To handle the deletion of the older unnecessary log files, we create a schedule job to run regularly to delete the logs older than 15 days.

GSX Gizmo 1.3+ | PostgreSQL


  1. Open Notepad
  2. Paste the following PowerShell command:
    • $start = (get-date).AddDays(-15) 
      Get-ChildItem -Path C:\ProgramData\PostgreSQL\10\Data\log\*.log | where {$PSItem.LastWriteTime -lt $start} | Remove-Item
  3. Save as a LogClean.ps1 file for example:
    • TaskScheduler3.png
  4. Open the Windows Task Scheduler
    • You can locate the Windows Task Scheduler by searching for it in the Windows Start Menu.
  5. Select Create Basic Task:
  6. Name the task, such as Clean Up Log Files and click Next:
  7. Select a timeframe for a Daily Trigger when the server is not busy, such as 4AM:
  8. Click Next and select Start a program:
  9. Click Browse... and select the .ps1 file created in Step 1 and click Next:
  10. Select the Open the Properties dialog box for this task when I click Finish option:
  11. Then click Run whether user is logged on or not and Run with highest privileges:
  12. Click OK - Finish.

You now have a script that is set to run every day to clear the PostgreSQL Logs. You can also adjust the frequency of how often the script runs if necessary.

PostgreSQL related article

Microsoft TechNet related article

Was this article helpful?

1 out of 1 found this helpful

Not finding what you are looking for?

Have more questions? Submit a request