1

Running PostgresSQL 11.4 on Windows 10

I made a DB cluster in C:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1

I registered that cluster to start on as a windows service on startup:

pg_ctl register -D C:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1 -N PostgreSQLdb1 -U WindowsUser -P WindowsPassword  -S a 

And the Where to log In C:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1\postgresql.conf I changed the log parameter to a absolute location.:

# - Where to Log -
log_destination = 'stderr'      # Valid values are combinations of
          # stderr, csvlog, syslog, and eventlog,
          # depending on platform.  csvlog
          # requires logging_collector to be on.
# This is used when logging to stderr:
logging_collector = on      # Enable capturing of stderr and csvlog
          # into log files. Required to be on for
          # csvlogs.
          # (change requires restart)
# These are only used if logging_collector is on:
log_directory = 'C:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1\log' 
                      # directory where log files are written,
          # can be absolute or relative to PGDATA
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, 
          # can include strftime() escapes

However, the cluster database does not write anything to log. The main PG database is located in a totally different directory, and that database does write to its log file.

Both databases works just fine, except the log part.

I have have even restarted my PC, but it still does not write to log.

7
  • Try to start the database from the command line using pg_ctl start -D :\Users\WindowsUser\AppData\Roaming\postgresql\Db_:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1 (after stopping the service). That should show you potential problems. Perhaps the permissions are wrong? Oct 14, 2019 at 11:07
  • That gave me an error: pg_ctl: directory ":/Users/WindowsUser/AppData/Roaming/postgresql/Db_:/Users/WindowsUser/AppData/Roaming/postgresql/Db_1" does not exist . However this does work if a specify a specific log file: pg_ctl start -D "C:\Users\WindowsUser\AppData\Ro" -l "C:\Users\WindowsUser\AppData\Ro\log\postgresql-2019-10-14.log" Oct 14, 2019 at 11:15
  • Well, does the directory exist? If it does, are the privileges setup correctly, so that the service account that runs Postgres (WindowsUser) can write into that directory? Unrelated, but I prefer a relative directory: log_directory = 'log'
    – user1822
    Oct 14, 2019 at 13:28
  • Sorry, I meant pg_ctl start -D C:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1. Hmm. Your question has a Roaming in there, your comment doesn't. What's going on there? Try to change log_directory in postgresql.conf. If that causes a log file to be written, then it must be some kind of permission problem. Oct 14, 2019 at 13:42
  • Ok, so my previous comment missed a few characters. I got it working when I entered a specified log file with the manual pg_ctl start -D "C:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1" -l "C:\Users\WindowsUser\AppData\Roaming\postgresql\Db_1\log\db1_logfile.log". I also tried with log_directory = 'log', but when nothing happened, I tried with the absolute dir-path instead. The user WindowsUser is an admin, so it should have write privileges. However, I added my "answer" below with the event-log alternative. Oct 14, 2019 at 14:19

1 Answer 1

0

Ok, so I did not get the Log files to work. But instead I got the Windows event log to work.

In postgresql.conf I set these line uncommented with those options:

log_destination = 'eventlog'        # Valid values are combinations of
                    # stderr, csvlog, syslog, and eventlog,
                    # depending on platform.  csvlog
                    # requires logging_collector to be on.

# This is only relevant when logging to eventlog (win32):
# (change requires restart)
event_source = 'PostgreSQL'

log_statement = 'all'    # none, ddl, mod, all
  • To register The Event log to Windows, I followed these instructions

  • I entered this command: REGSVR32 "C:\Program Files\PostgreSQL\11\lib\pgevent.dll" and a pop-up dialog confirmed that the pgevent.dll was registerd to REGSVR32

  • Then I opened Windows Event Viewer

  • On the right hand side, I chose Create custom view and got this pop-up dialog. I just filtered by the event source.

Pop-up dialog to configure the custom view

Then i get a neat list of events.

Windows Event Viewer

Your Answer

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

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