pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Ullrich <chris@chrullrich.net>
To: pgsql-admin@postgresql.org
Subject: Why does the WAL writer sit on completed segments (on Windows)?
Date: Mon, 17 Apr 2017 17:00:35 +0200
Message-ID: <od2lad$df0$1@blaine.gmane.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>

Hello,

I just encountered a problem with my archive_command when using 7-Zip to 
compress the WAL file. PostgreSQL is 9.6.2, the EDB x64 build.

archive_command is set to a batch file that effectively runs:

     7z a -tgzip M:\y\archive\%f.gz %p

Whenever a segment is ready to be archived, I get three log entries like 
this:

     LOG:  archive command failed with exit code 2
     DETAIL:  The failed archive command was: G:\data-9.6\archive.cmd 
pg_xlog\000000010000000000000011 000000010000000000000011

     WARNING: The process cannot access the file because it is being 
used by another process.

The reason, as Process Monitor shows, is that the WAL writer process 
keeps the file open for about one second after the 
archive_status\*.ready file has been created. The archiver runs the 
archive_command "too early", resulting in the sharing [1] violation seen 
above.

It gives up after three attempts and tries again a minute later. That 
attempt then succeeds (except for when the checkpointer is _still_ 
sitting on the file; I've seen that twice now, too).

When 7-Zip starts, it tries to open the file with FILE_SHARE_READ only, 
which is sensible for an archiver that wants to prevent other people 
changing the input file while it is being read. Since the WAL writer has 
it open with write access, the attempt fails.

Is this a known, er, feature, or should I consider it a bug in PostgreSQL?

There is a workaround; it works when I let 7z read the file through an 
input redirection:

     7z a -tgzip -si M:\y\archive\%f.gz < %p

This always works, presumably because cmd opens the file with a more 
generous share mode.


[1] Nothing to do with file shares; pg_xlog and archive are on the same
     system. Share modes are the reason open files usually cannot be
     deleted on Windows.


Thanks,

-- 
Christian



-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin



view thread (8+ messages)  latest in thread

Message-ID: <od2lad$df0$1@blaine.gmane.org>
Permalink:  ../od2lad$df0$1@blaine.gmane.org/
Also on:    postgresql.org/message-id/od2lad$df0$1@blaine.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: chris@chrullrich.net
  Subject: Re: Why does the WAL writer sit on completed segments (on Windows)?
  In-Reply-To: <od2lad$df0$1@blaine.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox