<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>惜分飞 &#187; pg日志</title>
	<atom:link href="https://www.xifenfei.com/tag/pg%e6%97%a5%e5%bf%97/feed" rel="self" type="application/rss+xml" />
	<link>https://www.xifenfei.com</link>
	<description>提供7*24专业数据库(Oracle,SQL Server,MySQL,PostgreSQL等)恢复和技术支持@Tel:17813235971</description>
	<lastBuildDate>Thu, 22 Oct 2026 15:45:06 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>PostgreSQL运行日志管理</title>
		<link>https://www.xifenfei.com/2025/04/postgresql-pg_log.html</link>
		<comments>https://www.xifenfei.com/2025/04/postgresql-pg_log.html#comments</comments>
		<pubDate>Thu, 03 Apr 2025 14:40:58 +0000</pubDate>
		<dc:creator><![CDATA[惜分飞]]></dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[pg日志]]></category>
		<category><![CDATA[pg日志管理]]></category>

		<guid isPermaLink="false">https://www.xifenfei.com/?p=11398</guid>
		<description><![CDATA[联系：手机/微信(+86 17813235971) QQ(107644445)  &#8230; <a href="https://www.xifenfei.com/2025/04/postgresql-pg_log.html">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="xifenfeicopyright">
<p>联系：<a href="https://www.xifenfei.com/about_xifenfei" target="_blank">手机/微信(+86 17813235971)   QQ(107644445)</a><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&#038;uin=107644445&#038;site=qq&#038;menu=yes"><img src="https://www.xifenfei.com/wp-content/themes/img/site_qq.jpg" alt="QQ咨询惜分飞" title="QQ咨询惜分飞"/></a></p>
<p>标题：<a href="https://www.xifenfei.com/2025/04/postgresql-pg_log.html" target="_blank">PostgreSQL运行日志管理</a></p>
<p>作者：<a href="https://www.xifenfei.com" target="_blank">惜分飞</a>©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]</p>
</div>
<p>PostgreSQL目前配置中,不直接记录日志文件,这样的情况给数据库后期出现问题(特别是无法正常启动的情况)分析带来很大麻烦,不知道具体问题所在,建议在PG安装完成之后,启用日志功能,便于数据库运行状态检查和错误跟踪,主要日志参数涉及以下配置</p>
<pre class="brush: bash; title: ; notranslate">
log_destination = 'stderr'              # Valid values are combinations of
                                        # stderr, csvlog, jsonlog, syslog, and
                                        # eventlog, depending on platform.
                                        # csvlog and jsonlog require
                                        # logging_collector to be on.

# This is used when logging to stderr:
logging_collector = on          # Enable capturing of stderr, jsonlog,
                                        # and csvlog into log files. Required
                                        # to be on for csvlogs and jsonlogs.
                                        # (change requires restart)
//是否将日志重定向至文件中，默认是off。

# 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
//日志文件目录，默认是PGDATA的相对路径，即PGDATA的相对路径，即{PGDATA}/pg_log，也可以改为绝对路径。
//日志文件可能会非常多，建议将日志重定向到其他目录或分区。
//将此配置修改其他目录时，必须先创建此目录，并修改权限，使得postgres用户对该目录有写权限。

log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
                                        # can include strftime() escapes
log_file_mode = 0600                    # creation mode for log files,
                                        # begin with 0 to use octal notation
log_rotation_age = 1d                   # 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.
#log_truncate_on_rotation = off         # If on, an existing log file with 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.
//当日志文件已存在时，该配置如果为off，新生成的日志将在文件尾部追加，如果为on，则会覆盖原来的日志。
</pre>
<p>上述配置得到的结果如下</p>
<pre class="brush: bash; title: ; notranslate">
[postgres@xifenfei pg_log]$ pwd
/data/pg/15/data/pg_log
[postgres@xifenfei pg_log]$ ls -l
total 4
-rw------- 1 postgres postgres 1263 Apr  3 22:37 postgresql-2025-04-03_223117.log
</pre>
<p><a href="https://www.xifenfei.com/wp-content/uploads/2025/04/pglog.png"><img src="https://www.xifenfei.com/wp-content/uploads/2025/04/pglog.png" alt="pglog" width="2169" height="324" class="alignleft size-full wp-image-11399" /></a><br />
<hr />
<div id="crp_related"><ul><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/08/pg_wal_filename-logseq-mismatch.html" rel="bookmark" class="crp_title">pg_wal中文件的名称中的logseq和实际文件中的logseq不匹配</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/03/invalid-checkpoint-record.html" rel="bookmark" class="crp_title">pg启动报invalid checkpoint record处理</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/03/pg_control-rebuild.html" rel="bookmark" class="crp_title">pg_control丢失/损坏处理</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/03/pg-delete-recovery.html" rel="bookmark" class="crp_title">pg误删除数据恢复（PostgreSQL delete数据恢复）</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/12/sql-bak-0-lost-data.html" rel="bookmark" class="crp_title">模拟sql server故障备份完成恢复实现数据0丢失</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/08/pg-tablespace-database-schema.html" rel="bookmark" class="crp_title">PostgreSQL的表空间、数据库、用户之间的关系</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/08/postgresql-archive_mode.html" rel="bookmark" class="crp_title">PostgreSQL修改归档模式</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/12/pg-replace-oid-recovery.html" rel="bookmark" class="crp_title">PostgreSQL oid文件替换实现数据访问</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/03/pdu-pg-delete-recovery.html" rel="bookmark" class="crp_title">pg删除数据恢复&#8212;pdu恢复pg delete数据</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2021/03/makop-db-recovery.html" rel="bookmark" class="crp_title">.makop病毒加密数据库恢复</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/10/linux7-8-single-user.html" rel="bookmark" class="crp_title">redhat系列7/8进入单用户模式</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2015/06/%e5%9c%a8linux%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-9-4%e5%b9%b6%e5%90%af%e5%8a%a8%e5%92%8c%e5%85%b3%e9%97%ad%e6%95%b0%e6%8d%ae%e5%ba%93.html" rel="bookmark" class="crp_title">在linux上安装PostgreSQL 9.4并启动和关闭数据库</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>https://www.xifenfei.com/2025/04/postgresql-pg_log.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
