在终端中显示Postgres服务器日志输出并同时记录到日志 [英] Display Postgres server logs output in terminal and record to logs at same time

查看:732
本文介绍了在终端中显示Postgres服务器日志输出并同时记录到日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Postgres 9.1(在Mac OSX上进行Homebrew安装),我想更密切地监视我的postgres服务器。

I'm running Postgres 9.1 (Homebrew installation on Mac OSX) and I'd like to monitor my postgres server more closely.

我的问题与日志有关。我想让日志显示在终端窗格中。这是Postgres docs 关于日志的说法:

My question relates to logs. I'd like to get the logs displaying in a terminal pane. Here's what the Postgres docs say about the logs:

在类似Unix的系统上,默认情况下,服务器的标准输出和标准错误将发送到pg_ctl的标准输出(不是标准错误)。然后,pg_ctl的标准输出应在Windows上,默认情况下,服务器将其重定向到文件或通过管道传递到另一个进程(例如,rotatelogs之类的日志旋转程序);否则postgres会将其输出(从后台)写入控制终端,并且不会离开外壳程序的进程组。标准输出和标准错误发送到终端。可以通过使用-l将服务器的输出附加到日志文件来更改这些默认行为。建议使用-l或输出重定向。

"On Unix-like systems, by default, the server's standard output and standard error are sent to pg_ctl's standard output (not standard error). The standard output of pg_ctl should then be redirected to a file or piped to another process such as a log rotating program like rotatelogs; otherwise postgres will write its output to the controlling terminal (from the background) and will not leave the shell's process group. On Windows, by default the server's standard output and standard error are sent to the terminal. These default behaviors can be changed by using -l to append the server's output to a log file. Use of either -l or output redirection is recommended."

因此,当我以以下命令运行Postgres服务器时:

So, when I get my postgres server running with the following:

pg_ctl start -D /usr/local/var/postgres

日志显示在终端窗口中。当我运行时:

The logs display in the terminal window. When I run:

pg_ctl start -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log

日志进入我的日志文件,而不显示在终端中。

the logs go to my logfile and don't display in terminal.

简而言之,如果有人告诉我将日志定向到文件(使用第二个命令)以使日志也出现在该文件后,我可以使用什么命令,那将是很棒的命令行。当我正在开发中(在Django中)观看SQL语句实时执行时,它会有所帮助。

In short, it would be great if anyone can tell me what command I use after I've directed logs to the file (with the second command) to make the logs also appear at the command line. It helps when I'm developing (in Django) to watch the SQL statements get executed in real time.

推荐答案

您可以观看使用以下命令登录日志:

You could watch the log with the command:

tail -f /usr/local/var/postgres/server.log

这篇关于在终端中显示Postgres服务器日志输出并同时记录到日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆