Server IP : 103.119.228.120 / Your IP : 18.118.154.237 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/local/ssl/local/ssl/share/doc/postgresql-9.2.24/html/ |
Upload File : |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Log File Maintenance</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 9.2.24 Documentation" HREF="index.html"><LINK REL="UP" TITLE="Routine Database Maintenance Tasks" HREF="maintenance.html"><LINK REL="PREVIOUS" TITLE="Routine Reindexing" HREF="routine-reindex.html"><LINK REL="NEXT" TITLE="Backup and Restore" HREF="backup.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2017-11-06T22:43:11"></HEAD ><BODY CLASS="SECT1" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" ><A HREF="index.html" >PostgreSQL 9.2.24 Documentation</A ></TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A TITLE="Routine Reindexing" HREF="routine-reindex.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="maintenance.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" >Chapter 23. Routine Database Maintenance Tasks</TD ><TD WIDTH="20%" ALIGN="right" VALIGN="top" ><A TITLE="Backup and Restore" HREF="backup.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="LOGFILE-MAINTENANCE" >23.3. Log File Maintenance</A ></H1 ><P > It is a good idea to save the database server's log output somewhere, rather than just discarding it via <TT CLASS="FILENAME" >/dev/null</TT >. The log output is invaluable when diagnosing problems. However, the log output tends to be voluminous (especially at higher debug levels) so you won't want to save it indefinitely. You need to <SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >rotate</I ></SPAN > the log files so that new log files are started and old ones removed after a reasonable period of time. </P ><P > If you simply direct the <SPAN CLASS="SYSTEMITEM" >stderr</SPAN > of <TT CLASS="COMMAND" >postgres</TT > into a file, you will have log output, but the only way to truncate the log file is to stop and restart the server. This might be acceptable if you are using <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > in a development environment, but few production servers would find this behavior acceptable. </P ><P > A better approach is to send the server's <SPAN CLASS="SYSTEMITEM" >stderr</SPAN > output to some type of log rotation program. There is a built-in log rotation facility, which you can use by setting the configuration parameter <TT CLASS="VARNAME" >logging_collector</TT > to <TT CLASS="LITERAL" >true</TT > in <TT CLASS="FILENAME" >postgresql.conf</TT >. The control parameters for this program are described in <A HREF="runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHERE" >Section 18.8.1</A >. You can also use this approach to capture the log data in machine readable <ACRONYM CLASS="ACRONYM" >CSV</ACRONYM > (comma-separated values) format. </P ><P > Alternatively, you might prefer to use an external log rotation program if you have one that you are already using with other server software. For example, the <SPAN CLASS="APPLICATION" >rotatelogs</SPAN > tool included in the <SPAN CLASS="PRODUCTNAME" >Apache</SPAN > distribution can be used with <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >. To do this, just pipe the server's <SPAN CLASS="SYSTEMITEM" >stderr</SPAN > output to the desired program. If you start the server with <TT CLASS="COMMAND" >pg_ctl</TT >, then <SPAN CLASS="SYSTEMITEM" >stderr</SPAN > is already redirected to <SPAN CLASS="SYSTEMITEM" >stdout</SPAN >, so you just need a pipe command, for example: </P><PRE CLASS="PROGRAMLISTING" >pg_ctl start | rotatelogs /var/log/pgsql_log 86400</PRE ><P> </P ><P > Another production-grade approach to managing log output is to send it to <SPAN CLASS="APPLICATION" >syslog</SPAN > and let <SPAN CLASS="APPLICATION" >syslog</SPAN > deal with file rotation. To do this, set the configuration parameter <TT CLASS="VARNAME" >log_destination</TT > to <TT CLASS="LITERAL" >syslog</TT > (to log to <SPAN CLASS="APPLICATION" >syslog</SPAN > only) in <TT CLASS="FILENAME" >postgresql.conf</TT >. Then you can send a <TT CLASS="LITERAL" >SIGHUP</TT > signal to the <SPAN CLASS="APPLICATION" >syslog</SPAN > daemon whenever you want to force it to start writing a new log file. If you want to automate log rotation, the <SPAN CLASS="APPLICATION" >logrotate</SPAN > program can be configured to work with log files from <SPAN CLASS="APPLICATION" >syslog</SPAN >. </P ><P > On many systems, however, <SPAN CLASS="APPLICATION" >syslog</SPAN > is not very reliable, particularly with large log messages; it might truncate or drop messages just when you need them the most. Also, on <SPAN CLASS="PRODUCTNAME" >Linux</SPAN >, <SPAN CLASS="APPLICATION" >syslog</SPAN > will flush each message to disk, yielding poor performance. (You can use a <SPAN CLASS="QUOTE" >"<TT CLASS="LITERAL" >-</TT >"</SPAN > at the start of the file name in the <SPAN CLASS="APPLICATION" >syslog</SPAN > configuration file to disable syncing.) </P ><P > Note that all the solutions described above take care of starting new log files at configurable intervals, but they do not handle deletion of old, no-longer-useful log files. You will probably want to set up a batch job to periodically delete old log files. Another possibility is to configure the rotation program so that old log files are overwritten cyclically. </P ><P > <A HREF="http://pgfouine.projects.postgresql.org/" TARGET="_top" ><SPAN CLASS="PRODUCTNAME" >pgFouine</SPAN ></A > is an external project that does sophisticated log file analysis. <A HREF="https://bucardo.org/check_postgres/" TARGET="_top" ><SPAN CLASS="PRODUCTNAME" >check_postgres</SPAN ></A > provides Nagios alerts when important messages appear in the log files, as well as detection of many other extraordinary conditions. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="routine-reindex.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="backup.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Routine Reindexing</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="maintenance.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Backup and Restore</TD ></TR ></TABLE ></DIV ></BODY ></HTML >