pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: movead.li@highgo.ca <movead.li@highgo.ca>
To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched.
Date: Wed, 25 Sep 2019 16:09:46 +0800
Message-ID: <2019092516094390916424@highgo.ca> (raw )
References: <15929-ee2973046b882ad0@postgresql.org >
hello
There be a problem about pg_recvlogical tool as I described last mail,
and I have made a patch to solve the problem.
It stores the 'st_ino' while opening the output file, and check it when the
process is waked up. It will try to reopen the output file if the output file
stat has changed or disappeared.
What do you think about?
---
Highgo Software (Canada/China/Pakistan)
URL : www.highgo.ca
EMAIL: mailto:movead(dot)li(at)highgo(dot)ca
Attachments:
pg_recvlogical_problem_20190925.patch (application/octet-stream, 1.7K) download
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index af29dd7651..4057279737 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -210,6 +210,7 @@ StreamLogicalLog(void)
TimestampTz last_status = -1;
int i;
PQExpBuffer query;
+ ino_t ino_store = 0;
output_written_lsn = InvalidXLogRecPtr;
output_fsync_lsn = InvalidXLogRecPtr;
@@ -340,8 +341,12 @@ StreamLogicalLog(void)
if (fstat(outfd, &statbuf) != 0)
pg_log_error("could not stat file \"%s\": %m", outfile);
-
output_isfile = S_ISREG(statbuf.st_mode) && !isatty(outfd);
+ /*
+ * store the st_ino when open the file, to use to judge if
+ * the file has beed changed.
+ */
+ ino_store = statbuf.st_ino;
}
r = PQgetCopyData(conn, ©buf, 1);
@@ -402,6 +407,32 @@ StreamLogicalLog(void)
}
r = select(PQsocket(conn) + 1, &input_mask, NULL, NULL, timeoutptr);
+ if(output_isfile)
+ {
+ struct stat statbuf_check;
+
+ memset(&statbuf_check, 0, sizeof(struct stat));
+ if (stat(outfile, &statbuf_check) != 0)
+ {
+ pg_log_error("could not stat file \"%s\": %m", outfile);
+ }
+
+ /*
+ * If the old file is renamed and a new file is puted there, it will
+ * reopen the new file.
+ *
+ * If the old file is removed and no new file appear, it will create
+ * a new file and open it.
+ */
+ if(ino_store != statbuf_check.st_ino)
+ {
+ pg_log_info("stat of file \"%s\" has changed and will output to the new file",
+ outfile);
+ output_reopen = true;
+ continue;
+ }
+ }
+
if (r == 0 || (r < 0 && errno == EINTR))
{
/*
view thread (4+ messages) latest in thread
Message-ID: <2019092516094390916424@highgo.ca>
Permalink: ../2019092516094390916424@highgo.ca/
Also on: postgresql.org/message-id/2019092516094390916424@highgo.ca
copy link · copy postgr.es · copy git am
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: movead.li@highgo.ca
Subject: Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched.
In-Reply-To: <2019092516094390916424@highgo.ca>
References: <15929-ee2973046b882ad0@postgresql.org> <2019092516094390916424@highgo.ca>
* 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