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

Instructions

  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:
    TaskScheduler1.png
  6. Name the task, such as Clean Up Log Files and click Next:
    TaskScheduler2.png
  7. Select a timeframe for a Daily Trigger when the server is not busy, such as 4AM:
    TaskScheduler4.png
  8. Click Next and select Start a program:
    TaskScheduler5.png
  9. Click Browse... and select the .ps1 file created in Step 1 and click Next:
    TaskScheduler6.png
  10. Select the Open the Properties dialog box for this task when I click Finish option:
    TaskScheduler7.png 
  11. Then click Run whether user is logged on or not and Run with highest privileges:
    TaskScheduler8.png
  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



Not finding what you are looking for?

Have more questions? Submit a request


Was this article helpful?

1 out of 1 found this helpful