在PostgreSQL Windows服务中登录文件


11

我需要一种替代方法来运行以下命令:

C:\xxx\pgsql\bin\pg_ctl" -D "C:\xxx\pgsql\data" -l "C:\yyy\log\pgsql.log" start

这样,服务器将启动并登录到C:\yyy\log\pgsql.log。但是,当我尝试将服务器注册为服务时-没有可用的日志记录选项,并且服务器将记录到事件查看器。从pg_ctl文档中:

pg_ctl注册[-N服务名] [-U用户名] [-P密码] [-D数据目录] [-S a [uto] | d [emand]] [-w] [-t秒] [-s] [-o选项]

如何强制服务器登录文件?注意:我不想使用一键式安装程序,我只想使用解压缩的二进制文件。


请确保您启用了log_statementlog_statement = 'all'
克里斯-

Answers:


13

postgresql.conf在datadir中找到您的

找到看起来像这样的部分

#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - 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 = off                # 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 = 'pg_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
#log_truncate_on_rotation = off         # If on, an existing log file of the
                                        # same name as the new log file will be
                                        # truncated rather than appended to.
                                        # But such truncation only occurs on
                                        # time-driven rotation, not on restarts
                                        # or size-driven rotation.  Default is
                                        # off, meaning append to existing files
                                        # in all cases.
log_rotation_age = 7d                   # Automatic rotation of logfiles will
                                        # happen after that time.  0 disables.
#log_rotation_size = 10MB               # Automatic rotation of logfiles will
                                        # happen after that much log output.
                                        # 0 disables.

只需取消注释并使用这些参数即可。然后,重新启动postgres服务,

由于您在Windows中运行postgresql,因此postgresql.conf服务启动时可能不允许您进行编辑。如果是这样的话:

  • 关闭postgres服务
  • 编辑 postgresql.conf
  • 启动postgres服务

试试看 !!!


感谢您为我指明了正确的方向,罗兰多(Rolando),但您的回答并不正确...在引用配置文件时,您只能在stderr, csvlog, syslog, eventlog那里。我不得不更改以下属性:logging_collector = on, log_directory = ..., log_filename=...。如果您编辑答案,我会接受。
维克

1
嘿维克,谢谢。我是PostgreSQL的新手,并且为它提供了少量支持。我只是一个古老的国家MySQL DBA。
RolandoMySQLDBA 2012年

1
log_directory ='C:/ Users / Peter / Documents / jonbloe / system / logs'为我工作。但是请不要使用Windows'\',因为它会转义并且日志最终会存放在PGDATA / UsersPeterDocumentsjonbloesystemlogs文件夹中
peter2108'9
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.