pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #15929: logical decoding can not write down the analyse result when the output file is touched.
4+ messages / 3 participants
[nested] [flat]
* BUG #15929: logical decoding can not write down the analyse result when the output file is touched.
@ 2019-07-27 09:39 PG Bug reporting form <noreply@postgresql.org>
2019-09-25 08:09 ` Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched. movead.li@highgo.ca <movead.li@highgo.ca>
2019-09-27 21:35 ` Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched. Andres Freund <andres@anarazel.de>
0 siblings, 2 replies; 4+ messages in thread
From: PG Bug reporting form @ 2019-07-27 09:39 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: movead.li@highgo.ca
The following bug has been logged on the website:
Bug reference: 15929
Logged by: movead li
Email address: movead.li@highgo.ca
PostgreSQL version: 12beta1
Operating system: centos7
Description:
I was doing some testing of logical decoding and ran into a scenario that
may be a bug. The following steps will lead to reproducing the behaviour :
1.Start a logical decoding use below command:
pg_recvlogical -d postgres --slot=test2 --create-slot
pg_recvlogical -d postgres --slot=test2 --start -f ld.log
2. When I do a DML on the database it writes down the info into ld.log
file,
so far so good.
3. Next I open the log file. “Id.log” with vi and make some arbitrary
changes
in the log file.
4. If I run a DML command now the DML info will not appear in the ld.log
file.
Refer to step 2, when I did a DML it was appearing in the log file.
5. If I do some manipulation with the log file using the OS commands below :
mv ld.log ld.log1;
cp ld.log1 ld.log;
Then the DML info will start appearing in file ld.log1.
This seems like a bug to be because the user might accidentally some data
without noticing.
I have looked at the code to debug this behaviour and find a solution
In file ‘pg_recvlogical.c’ the ‘StreamLogicalLog()’ function seem to have
a
issue with handling of DML info. It uses open() to open the file and it does
not
check the file state when writing to the file after a long wait.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched.
2019-07-27 09:39 BUG #15929: logical decoding can not write down the analyse result when the output file is touched. PG Bug reporting form <noreply@postgresql.org>
@ 2019-09-25 08:09 ` movead.li@highgo.ca <movead.li@highgo.ca>
1 sibling, 0 replies; 4+ messages in thread
From: movead.li@highgo.ca @ 2019-09-25 08:09 UTC (permalink / raw)
To: pgsql-bugs <pgsql-bugs@lists.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))
{
/*
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched.
2019-07-27 09:39 BUG #15929: logical decoding can not write down the analyse result when the output file is touched. PG Bug reporting form <noreply@postgresql.org>
@ 2019-09-27 21:35 ` Andres Freund <andres@anarazel.de>
2019-10-16 06:57 ` Re: Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched. movead.li@highgo.ca <movead.li@highgo.ca>
1 sibling, 1 reply; 4+ messages in thread
From: Andres Freund @ 2019-09-27 21:35 UTC (permalink / raw)
To: movead.li@highgo.ca; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-07-27 09:39:47 +0000, PG Bug reporting form wrote:
> I was doing some testing of logical decoding and ran into a scenario that
> may be a bug. The following steps will lead to reproducing the behaviour :
>
>
> 1.Start a logical decoding use below command:
>
> pg_recvlogical -d postgres --slot=test2 --create-slot
> pg_recvlogical -d postgres --slot=test2 --start -f ld.log
>
> 2. When I do a DML on the database it writes down the info into ld.log
> file,
> so far so good.
>
> 3. Next I open the log file. “Id.log” with vi and make some arbitrary
> changes
> in the log file.
>
> 4. If I run a DML command now the DML info will not appear in the ld.log
> file.
> Refer to step 2, when I did a DML it was appearing in the log file.
>
> 5. If I do some manipulation with the log file using the OS commands below :
>
>
> mv ld.log ld.log1;
> cp ld.log1 ld.log;
>
> Then the DML info will start appearing in file ld.log1.
>
> This seems like a bug to be because the user might accidentally some data
> without noticing.
>
> I have looked at the code to debug this behaviour and find a solution
>
> In file ‘pg_recvlogical.c’ the ‘StreamLogicalLog()’ function seem to have
> a
> issue with handling of DML info. It uses open() to open the file and it does
> not
> check the file state when writing to the file after a long wait.
I don't see a bug here. It's completely normal for a tool that writes to
a file to continue writing into the file it started to write to. The
reason that vi breaks that is presumably just that it renames the
"edited" version into the place of the file that pg_recvlogical is still
writing to.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched.
2019-07-27 09:39 BUG #15929: logical decoding can not write down the analyse result when the output file is touched. PG Bug reporting form <noreply@postgresql.org>
2019-09-27 21:35 ` Re: BUG #15929: logical decoding can not write down the analyse result when the output file is touched. Andres Freund <andres@anarazel.de>
@ 2019-10-16 06:57 ` movead.li@highgo.ca <movead.li@highgo.ca>
0 siblings, 0 replies; 4+ messages in thread
From: movead.li@highgo.ca @ 2019-10-16 06:57 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>
>I don't see a bug here. It's completely normal for a tool that writes to
>a file to continue writing into the file it started to write to. The
>reason that vi breaks that is presumably just that it renames the
>"edited" version into the place of the file that pg_recvlogical is still
>writing to.
It is the issue that the target file is changed but the 'pg_recvlogical'
process doesn't know it at all. So it streams all wal changes but writes
down nothing at last.
So I think we can recreate or reopen the changed file when there be
something wrong with the target file. And we can choose to kill the
'pg_recvlogical' process because it's no use at all now, or we should
give a warning to users at lease.
---
Highgo Software (Canada/China/Pakistan)
URL : www.highgo.ca
EMAIL: mailto:movead(dot)li(at)highgo(dot)ca
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-10-16 06:57 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-27 09:39 BUG #15929: logical decoding can not write down the analyse result when the output file is touched. PG Bug reporting form <noreply@postgresql.org>
2019-09-25 08:09 ` movead.li@highgo.ca <movead.li@highgo.ca>
2019-09-27 21:35 ` Andres Freund <andres@anarazel.de>
2019-10-16 06:57 ` movead.li@highgo.ca <movead.li@highgo.ca>
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