Re: [DOCS] max_worker_processes on the standby

Started by Alvaro Herreraover 10 years ago26 messageshackersdocs
Jump to latest
#1Alvaro Herrera
alvherre@2ndquadrant.com
hackersdocs

oonishitk@nttdata.co.jp wrote:

The below error messages were shown in standby server log:

FATAL: could not access status of transaction 9009
DETAIL: Could not read from file "pg_commit_ts/0000" at offset 90112: Success.
CONTEXT: xlog redo Transaction/COMMIT: 2015-09-30 15:52:41.924141+09
LOG: startup process (PID 23199) exited with exit code 1
LOG: terminating any other active server processes

Before this FATAL, there were some INFO but annoying messages:

LOG: file "pg_commit_ts/0000" doesn't exist, reading as zeroes

Here's a patch.

I went over the commit_ts.c code a few more times. I eventually
realized that we were trying to update the value of the GUC, which is a
rather unreliable thing to do; this was made worse by the fact that we
were updating it in one process only.

I thought it was better to have a separate boolean flag, affecting the
recovery process only, which is set at startup time or when the
XLOG_PARAMETER_CHANGE message is received. The module is enabled if
either the GUC is set or we see that the master has the module enabled.
This only enables it as far as replaying xlog records though: if you use
the SQL interface, it will still raise an error that you cannot read
values unless the GUC is enabled. This seems fine to me.

A curious but benign effect of this patch is that if you have the module
disabled in the master but enabled in the standby, you can actually
query the commit times in the standby, and they will correspond to
whatever the master used in the commit xlog record.

Other small changes:

- Moved some code out of xlog_redo into a new public commit_ts.c
routine; made ActivateCommitTs and Deactivate* statics.

- In the previous commit I added an assert that we're not writing xlog
and replaying xlog at the same time. This is pointless because xlog.c
already complains about that, so this commit takes it out again.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

committs.patchtext/x-diff; charset=us-asciiDownload+73-63
#2Noname
oonishitk@nttdata.co.jp
In reply to: Alvaro Herrera (#1)
hackersdocs
Re: max_worker_processes on the standby

Here's a patch.

Thank you!
With this patch, the standby server down disappears in my environment.

Regards,

========
Takashi Ohnishi
oonishitk@nttdata.co.jp

-----Original Message-----
From: Alvaro Herrera [mailto:alvherre@2ndquadrant.com]
Sent: Thursday, October 01, 2015 7:48 AM
To: Fujii Masao <masao.fujii@gmail.com>; SPS 大西 高史(三技術) <oonishitk@nttdata.co.jp>
Cc: pgsql-docs <pgsql-docs@postgresql.org>; pgsql-hackers@postgresql.org
Subject: Re: [DOCS] max_worker_processes on the standby

oonishitk@nttdata.co.jp wrote:

The below error messages were shown in standby server log:

FATAL: could not access status of transaction 9009
DETAIL: Could not read from file "pg_commit_ts/0000" at offset 90112: Success.
CONTEXT: xlog redo Transaction/COMMIT: 2015-09-30 15:52:41.924141+09
LOG: startup process (PID 23199) exited with exit code 1
LOG: terminating any other active server processes

Before this FATAL, there were some INFO but annoying messages:

LOG: file "pg_commit_ts/0000" doesn't exist, reading as zeroes

Here's a patch.

I went over the commit_ts.c code a few more times. I eventually realized that we were trying to update the value of the GUC, which is a rather unreliable thing to do; this was made worse by the fact that we were updating it in one process only.

I thought it was better to have a separate boolean flag, affecting the recovery process only, which is set at startup time or when the XLOG_PARAMETER_CHANGE message is received. The module is enabled if either the GUC is set or we see that the master has the module enabled.
This only enables it as far as replaying xlog records though: if you use the SQL interface, it will still raise an error that you cannot read values unless the GUC is enabled. This seems fine to me.

A curious but benign effect of this patch is that if you have the module disabled in the master but enabled in the standby, you can actually query the commit times in the standby, and they will correspond to whatever the master used in the commit xlog record.

Other small changes:

- Moved some code out of xlog_redo into a new public commit_ts.c routine; made ActivateCommitTs and Deactivate* statics.

- In the previous commit I added an assert that we're not writing xlog and replaying xlog at the same time. This is pointless because xlog.c already complains about that, so this commit takes it out again.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#3Fujii Masao
masao.fujii@gmail.com
In reply to: Alvaro Herrera (#1)
hackersdocs
Re: max_worker_processes on the standby

On Thu, Oct 1, 2015 at 7:48 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

oonishitk@nttdata.co.jp wrote:

The below error messages were shown in standby server log:

FATAL: could not access status of transaction 9009
DETAIL: Could not read from file "pg_commit_ts/0000" at offset 90112: Success.
CONTEXT: xlog redo Transaction/COMMIT: 2015-09-30 15:52:41.924141+09
LOG: startup process (PID 23199) exited with exit code 1
LOG: terminating any other active server processes

Before this FATAL, there were some INFO but annoying messages:

LOG: file "pg_commit_ts/0000" doesn't exist, reading as zeroes

Here's a patch.

I've not read the patch yet, but the patched server with track_commit_timestamp
enabled caused the following PANIC error when I ran pgbench.

PANIC: could not access status of transaction 2457
DETAIL: Could not read from file "pg_commit_ts/0000" at offset 24576: Success.
STATEMENT: END;

The procedure to reproduce the PANIC error is,

1. Enable track_commit_timestamp
2. Start up the server
3. Run pgbench -i -s10
4. Run pgbench -j 4 -c 4 -T 30

Regards,

--
Fujii Masao

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

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Fujii Masao (#3)
hackersdocs
Re: max_worker_processes on the standby

Fujii Masao wrote:

I've not read the patch yet, but the patched server with track_commit_timestamp
enabled caused the following PANIC error when I ran pgbench.

Ah, that was a stupid typo: I used || instead of &&. Fixed that.

I also changed DeactivateCommitTs() so that it removes all slru segments
instead of leaving the last one around (which is what SimpleLruTruncate
was doing). This was noticeable when you ran a server with the feature
enabled (which created some files), then disabled it (which removed all
but the last) and ran for some more xacts; then enabled it again (which
created a new file, far ahead from the previously existing one). Since
the feature has enough protections that it doesn't have a problem with
no files at all being present, this works correctly. Note no
wal-logging of this operation: it's not necessary AFAICS because the
same deactivation routine would be called again in recovery and in
XLOG_PARAMETER_CHANGE, so it should be safe.

And pushed.

Thanks!

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#5Fujii Masao
masao.fujii@gmail.com
In reply to: Alvaro Herrera (#4)
hackersdocs

On Fri, Oct 2, 2015 at 3:12 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Fujii Masao wrote:

I've not read the patch yet, but the patched server with track_commit_timestamp
enabled caused the following PANIC error when I ran pgbench.

Ah, that was a stupid typo: I used || instead of &&. Fixed that.

I also changed DeactivateCommitTs() so that it removes all slru segments
instead of leaving the last one around (which is what SimpleLruTruncate
was doing). This was noticeable when you ran a server with the feature
enabled (which created some files), then disabled it (which removed all
but the last) and ran for some more xacts; then enabled it again (which
created a new file, far ahead from the previously existing one). Since
the feature has enough protections that it doesn't have a problem with
no files at all being present, this works correctly. Note no
wal-logging of this operation: it's not necessary AFAICS because the
same deactivation routine would be called again in recovery and in
XLOG_PARAMETER_CHANGE, so it should be safe.

What happens if pg_xact_commit_timestamp() is called in standby after
track_commit_timestamp is disabled in master, DeactivateCommitTs() is
called and all commit_ts files are removed in standby? I tried that case
and got the following assertion failure.

TRAP: FailedAssertion("!(((oldestCommitTs) != ((TransactionId) 0)) ==
((newestCommitTs) != ((TransactionId) 0)))", File: "commit_ts.c",
Line: 307)

LOG: server process (PID 11160) was terminated by signal 6: Aborted
DETAIL: Failed process was running: select num,
pg_xact_commit_timestamp(num::text::xid) from generate_series(1750,
1800) num

The steps to reproduce the problem is

1. Set up replication with track_commit_timestamp enabled.
2. Run several write transactions.
3. Disable track_commit_timestamp only in master and wait for
XLOG_PARAMETER_CHANGE record to be replayed in standby.
4. Run pg_xact_commit_timestamp() in standby.

Regards,

--
Fujii Masao

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

#6Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Fujii Masao (#5)
hackersdocs
Re: max_worker_processes on the standby

Fujii Masao wrote:

What happens if pg_xact_commit_timestamp() is called in standby after
track_commit_timestamp is disabled in master, DeactivateCommitTs() is
called and all commit_ts files are removed in standby? I tried that case
and got the following assertion failure.

Ah. So the standby needs to keep the module activated if it's enabled
locally, even when it receives a message that the master turned it off.
Here's a patch.

Thanks for your continued testing!

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

committs.patchtext/x-diff; charset=us-asciiDownload+3-2
#7Robert Haas
robertmhaas@gmail.com
In reply to: Alvaro Herrera (#6)
hackersdocs
Re: max_worker_processes on the standby

On Fri, Oct 2, 2015 at 10:58 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

Fujii Masao wrote:

What happens if pg_xact_commit_timestamp() is called in standby after
track_commit_timestamp is disabled in master, DeactivateCommitTs() is
called and all commit_ts files are removed in standby? I tried that case
and got the following assertion failure.

Ah. So the standby needs to keep the module activated if it's enabled
locally, even when it receives a message that the master turned it off.
Here's a patch.

The standby can have the feature enabled even though the master has it
disabled? That seems like it can only lead to heartache.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

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

#8Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Robert Haas (#7)
hackersdocs
Re: max_worker_processes on the standby

Robert Haas wrote:

The standby can have the feature enabled even though the master has it
disabled? That seems like it can only lead to heartache.

Can you elaborate?

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#9Robert Haas
robertmhaas@gmail.com
In reply to: Alvaro Herrera (#8)
hackersdocs
Re: max_worker_processes on the standby

On Fri, Oct 2, 2015 at 2:59 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Robert Haas wrote:

The standby can have the feature enabled even though the master has it
disabled? That seems like it can only lead to heartache.

Can you elaborate?

Sort of. Our rule up until now has always been that the standby is an
exact copy of the master. I suspect deviating from that behavior will
introduce bugs. I suspect having the standby make data changes that
aren't WAL-logged will introduce bugs; not to be unkind, but that
certainly seems like a lesson to take from what happened with
multixacts.

I haven't looked at this code well enough to guess specifically what
will go wrong. But consider people turning the feature on and off
repeatedly on the master, and separately on the standby, combined with
crashes on the standby that restart replay from earlier points
(possibly with settings that have changed in the meantime). Are we
really sure that we're never going to end up with the wrong files, or
inconsistent ones, on the standby? I have a really hard time
believing that's going to work out.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

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

#10Fujii Masao
masao.fujii@gmail.com
In reply to: Alvaro Herrera (#6)
hackersdocs
Re: max_worker_processes on the standby

On Fri, Oct 2, 2015 at 11:58 PM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

Fujii Masao wrote:

What happens if pg_xact_commit_timestamp() is called in standby after
track_commit_timestamp is disabled in master, DeactivateCommitTs() is
called and all commit_ts files are removed in standby? I tried that case
and got the following assertion failure.

Ah. So the standby needs to keep the module activated if it's enabled
locally, even when it receives a message that the master turned it off.
Here's a patch.

I'm afraid that this behavior might confuse the users.

Please imagine the following scenario.

1. start up the server with track_commit_timestamp disabled
2. run several transactions
3. shut down the server with immediate mode
4. restart the server with track_commit_timestamp enabled
5. run "SELECT pg_last_committed_xact()"
6. run "SELECT pg_xact_commit_timestamp(xid) FROM pg_last_committed_xact()"
7. restart the server
8. run "SELECT pg_last_committed_xact()"

Firstly, in #5, pg_last_committed_xact() returns the XID and
timestamp of the last transaction which was executed in #2
(i.e., while track_commit_timestamp was disabled).
This is confusing. I think that both pg_last_committed_xact()
and pg_xact_commit_timestamp() should return only the transaction
which was executed with track_commit_timestamp enabled.

Secondly, SELECT query in #6 returns NULL. This means that
pg_xact_commit_timestamp() may not handle the transaction
which pg_last_committed_xact() handles. This is also confusing.

Finally, in #8, pg_last_committed_xact() returns NULL while
it returned non-NULL before the restart. This is also confusing.

Regards,

--
Fujii Masao

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

#11Petr Jelinek
petr@2ndquadrant.com
In reply to: Robert Haas (#9)
hackersdocs
Re: [HACKERS] max_worker_processes on the standby

On 2015-10-02 22:02, Robert Haas wrote:

On Fri, Oct 2, 2015 at 2:59 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Robert Haas wrote:

The standby can have the feature enabled even though the master has it
disabled? That seems like it can only lead to heartache.

Can you elaborate?

Sort of. Our rule up until now has always been that the standby is an
exact copy of the master. I suspect deviating from that behavior will
introduce bugs. I suspect having the standby make data changes that
aren't WAL-logged will introduce bugs; not to be unkind, but that
certainly seems like a lesson to take from what happened with
multixacts.

I agree with that sentiment.

Attached patch adds variable to the shmem which is used for module
activation tracking - set to true in ActiveCommitTs() and false in
DeactivateCommitTs(). All the checks inside the commit_ts code were
changed to use this new variable. I also removed the static variable
Alvaro added in previous commit because it's not needed anymore.

The patch also does full cleanup of the shmem state in
DeactivateCommitTs() so that standby does not have stale last committed
transaction info after enable/disable/enable cycle on primary

I also removed no longer used do_wal parameters in couple of functions.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

committs-activation-fixes.patchapplication/x-patch; name=committs-activation-fixes.patchDownload+42-33
#12Robert Haas
robertmhaas@gmail.com
In reply to: Petr Jelinek (#11)
hackersdocs
Re: [HACKERS] max_worker_processes on the standby

On Sat, Oct 17, 2015 at 5:37 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I agree with that sentiment.

Attached patch adds variable to the shmem which is used for module
activation tracking - set to true in ActiveCommitTs() and false in
DeactivateCommitTs(). All the checks inside the commit_ts code were changed
to use this new variable. I also removed the static variable Alvaro added in
previous commit because it's not needed anymore.

That sounds good to me. On a quick read-through it looks OK too.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

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

#13Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Robert Haas (#12)
hackersdocs
Re: [HACKERS] max_worker_processes on the standby

Robert Haas wrote:

On Sat, Oct 17, 2015 at 5:37 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I agree with that sentiment.

Attached patch adds variable to the shmem which is used for module
activation tracking - set to true in ActiveCommitTs() and false in
DeactivateCommitTs(). All the checks inside the commit_ts code were changed
to use this new variable. I also removed the static variable Alvaro added in
previous commit because it's not needed anymore.

That sounds good to me. On a quick read-through it looks OK too.

A revised version is attached. Two changes on top of Petr's patch:

1. In the two "get" routines, we were reading the flag without grabbing
the lock. This is okay in a master server, because the flag cannot
change in flight, but in a standby it is possible to have the module
be deactivated while TS data is being queried. To fix this, simply move
the check for the active shmem flag a few lines down to be inside the
locked section.

There are two other places that also read the flag without grabbing the
lock. These look okay to me, so I added comments stating so.

2. In TransactionIdGetCommitTsData() we were grabbing lock, reading some
data, releasing lock, then examining the "cached" value in shmem without
a lock to see if it matched the function argument; if it's match, grab
lock again and return the correct data. In the original coding this
made sense because there was no locked section prior to reading the
cache, but after the patch this was pointless. Make it simpler by
moving the read of the cache inside the locked section too.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

committs-activation-fixes-2.patchtext/x-diff; charset=us-asciiDownload+83-74
#14Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#13)
hackersdocs

Alvaro Herrera wrote:

Robert Haas wrote:

On Sat, Oct 17, 2015 at 5:37 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I agree with that sentiment.

Attached patch adds variable to the shmem which is used for module
activation tracking - set to true in ActiveCommitTs() and false in
DeactivateCommitTs(). All the checks inside the commit_ts code were changed
to use this new variable. I also removed the static variable Alvaro added in
previous commit because it's not needed anymore.

That sounds good to me. On a quick read-through it looks OK too.

A revised version is attached.

Pushed.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#15Fujii Masao
masao.fujii@gmail.com
In reply to: Alvaro Herrera (#14)
hackersdocs

On Wed, Oct 28, 2015 at 3:07 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

Alvaro Herrera wrote:

Robert Haas wrote:

On Sat, Oct 17, 2015 at 5:37 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I agree with that sentiment.

Attached patch adds variable to the shmem which is used for module
activation tracking - set to true in ActiveCommitTs() and false in
DeactivateCommitTs(). All the checks inside the commit_ts code were changed
to use this new variable. I also removed the static variable Alvaro added in
previous commit because it's not needed anymore.

That sounds good to me. On a quick read-through it looks OK too.

A revised version is attached.

Pushed.

I found another strange behavior on track_commit_timestamp.
Here are the steps to reproduce it.

1. Start the master and standby servers with track_commit_timestamp enabled.
Since committs is activated in standby, pg_last_committed_xact() can
successfully return the timestamp of last transaction as expected.

2. Disable track_commit_timestamp in the master and restart the master server.
The parameter-change WAL record is streamed to the standby and committs
is deactivated. pg_last_committed_xact() causes an ERROR in the standby.

3. Run checkpoint in the master.

4. Run restartpoint in the standby after the checkpoint WAL record generated
in #3 is replicated to the standby.

5. Restart the standby server.
Committs is activated in the standby because track_commit_timestamp is
enabled. Since there is no parameter-change WAL record since last
restartpoint, committs is not deactivated. So pg_last_committed_xact()
can successfully return the timestamp.

6. Enable track_commit_timestamp in the master and restart the master server.

7. Disable track_commit_timestamp in the master and restart the master server.
Back to the same situation as #2. That is, pg_last_committed_xact() causes
an ERROR.

8. Promote the standby server to new master.
Since committs is still inactive even after the promotion,
pg_last_committed_xact() keeps causing an ERROR though
track_commit_timestamp is on.

What I think strange is that pg_last_committed_xact() behaves differently
in #2, #5, and #7 though the settings of track_commit_timestamp are same
in both servers, i.e., it's disabled in the master but enabled in the standby.

I was thinking that whether committs is active or not should depend on
the setting of track_commit_timestamp *after* the promotion.
The behavior in #8 looked strange.

Regards,

--
Fujii Masao

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

#16Robert Haas
robertmhaas@gmail.com
In reply to: Fujii Masao (#15)
hackersdocs
Re: [HACKERS] max_worker_processes on the standby

On Thu, Oct 29, 2015 at 5:41 PM, Fujii Masao <masao.fujii@gmail.com> wrote:

I found another strange behavior on track_commit_timestamp.
Here are the steps to reproduce it.

1. Start the master and standby servers with track_commit_timestamp enabled.
Since committs is activated in standby, pg_last_committed_xact() can
successfully return the timestamp of last transaction as expected.

2. Disable track_commit_timestamp in the master and restart the master server.
The parameter-change WAL record is streamed to the standby and committs
is deactivated. pg_last_committed_xact() causes an ERROR in the standby.

3. Run checkpoint in the master.

4. Run restartpoint in the standby after the checkpoint WAL record generated
in #3 is replicated to the standby.

5. Restart the standby server.
Committs is activated in the standby because track_commit_timestamp is
enabled.

This seems wrong already at this point.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

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

#17Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Fujii Masao (#15)
hackersdocs
Re: [HACKERS] max_worker_processes on the standby

I paraphrase Fujii Masao, who wrote:

1. Start the master and standby servers with track_commit_timestamp enabled.
2. Disable track_commit_timestamp in the master and restart the master server.
3. Run checkpoint in the master.
4. Run restartpoint in the standby after the checkpoint WAL record generated
5. Restart the standby server.
6. Enable track_commit_timestamp in the master and restart the master server.
7. Disable track_commit_timestamp in the master and restart the master server.

What I think strange is that pg_last_committed_xact() behaves differently
in #2, #5, and #7 though the settings of track_commit_timestamp are same
in both servers, i.e., it's disabled in the master but enabled in the standby.

Interesting, thanks. You're right that this behaves oddly.

I think in order to fix these two points (#5 and #7), we need to make
the standby not honour the GUC at all, i.e. only heed what the master
setting is.

8. Promote the standby server to new master.
Since committs is still inactive even after the promotion,
pg_last_committed_xact() keeps causing an ERROR though
track_commit_timestamp is on.

I was thinking that whether committs is active or not should depend on
the setting of track_commit_timestamp *after* the promotion.
The behavior in #8 looked strange.

To fix this problem, we can re-run StartupCommitTs() after recovery is
done, this time making sure to honour the GUC setting.

I haven't tried the scenarios we fixed with the previous round of
patching, but this patch seems to close the problems just reported.
(My next step will be looking over the recovery test framework by
Michael et al, so that I can apply a few tests for this stuff.)
In the meantime, if you can look this over I would appreciate it.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

committs.patchtext/x-diff; charset=us-asciiDownload+6-6
#18Petr Jelinek
petr@2ndquadrant.com
In reply to: Alvaro Herrera (#17)
hackersdocs

On 2015-11-16 22:43, Alvaro Herrera wrote:

I paraphrase Fujii Masao, who wrote:

1. Start the master and standby servers with track_commit_timestamp enabled.
2. Disable track_commit_timestamp in the master and restart the master server.
3. Run checkpoint in the master.
4. Run restartpoint in the standby after the checkpoint WAL record generated
5. Restart the standby server.
6. Enable track_commit_timestamp in the master and restart the master server.
7. Disable track_commit_timestamp in the master and restart the master server.

What I think strange is that pg_last_committed_xact() behaves differently
in #2, #5, and #7 though the settings of track_commit_timestamp are same
in both servers, i.e., it's disabled in the master but enabled in the standby.

Interesting, thanks. You're right that this behaves oddly.

I think in order to fix these two points (#5 and #7), we need to make
the standby not honour the GUC at all, i.e. only heed what the master
setting is.

8. Promote the standby server to new master.
Since committs is still inactive even after the promotion,
pg_last_committed_xact() keeps causing an ERROR though
track_commit_timestamp is on.

I was thinking that whether committs is active or not should depend on
the setting of track_commit_timestamp *after* the promotion.
The behavior in #8 looked strange.

To fix this problem, we can re-run StartupCommitTs() after recovery is
done, this time making sure to honour the GUC setting.

I haven't tried the scenarios we fixed with the previous round of
patching, but this patch seems to close the problems just reported.
(My next step will be looking over the recovery test framework by
Michael et al, so that I can apply a few tests for this stuff.)
In the meantime, if you can look this over I would appreciate it.

While this seems good, I'd code it slightly differently. I didn't like
the addition of new bool when it's not really needed. This brings the
question if we actually need the BootStrapCommitTs and StartupCommitTs
functions which really don't do much though.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

committs-activation-fix.patchbinary/octet-stream; name=committs-activation-fix.patchDownload+5-5
#19Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Petr Jelinek (#18)
hackersdocs

Petr Jelinek wrote:

While this seems good, I'd code it slightly differently. I didn't like the
addition of new bool when it's not really needed. This brings the question
if we actually need the BootStrapCommitTs and StartupCommitTs functions
which really don't do much though.

Thanks, it's certainly nice that this got simpler. (I'm not in love
with the idea of having xlog.c know what flag needs to pass in each
case, but I don't see any option that's more convenient.)

We weren't quite there however -- namely this patch didn't close problem
#8 in Fujii-san rundown. The problem is that when promoting,
standbyState is not STANDBY_DISABLED but STANDBY_SNAPSHOT_READY (which
is a bit surprising but not something this patch should fix). To fix
this I took the StartupCommitTs() call out of that block, so that it
runs inconditionally.

I also changed the hint message:

postgres=# select * from pg_last_committed_xact();
ERROR: could not get commit timestamp data
HINT: Make sure the configuration parameter "track_commit_timestamp" is set in the master server.

Otherwise this would be very confusing:

postgres=# select * from pg_last_committed_xact();
ERROR: could not get commit timestamp data
HINT: Make sure the configuration parameter "track_commit_timestamp" is set.
postgres=# show track_commit_timestamp ;
track_commit_timestamp
------------------------
on
(1 fila)

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#20Fujii Masao
masao.fujii@gmail.com
In reply to: Alvaro Herrera (#17)
hackersdocs

On Tue, Nov 17, 2015 at 6:43 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

I paraphrase Fujii Masao, who wrote:

1. Start the master and standby servers with track_commit_timestamp enabled.
2. Disable track_commit_timestamp in the master and restart the master server.
3. Run checkpoint in the master.
4. Run restartpoint in the standby after the checkpoint WAL record generated
5. Restart the standby server.
6. Enable track_commit_timestamp in the master and restart the master server.
7. Disable track_commit_timestamp in the master and restart the master server.

What I think strange is that pg_last_committed_xact() behaves differently
in #2, #5, and #7 though the settings of track_commit_timestamp are same
in both servers, i.e., it's disabled in the master but enabled in the standby.

Interesting, thanks. You're right that this behaves oddly.

I think in order to fix these two points (#5 and #7), we need to make
the standby not honour the GUC at all, i.e. only heed what the master
setting is.

8. Promote the standby server to new master.
Since committs is still inactive even after the promotion,
pg_last_committed_xact() keeps causing an ERROR though
track_commit_timestamp is on.

I was thinking that whether committs is active or not should depend on
the setting of track_commit_timestamp *after* the promotion.
The behavior in #8 looked strange.

To fix this problem, we can re-run StartupCommitTs() after recovery is
done, this time making sure to honour the GUC setting.

I haven't tried the scenarios we fixed with the previous round of
patching, but this patch seems to close the problems just reported.
(My next step will be looking over the recovery test framework by
Michael et al, so that I can apply a few tests for this stuff.)
In the meantime, if you can look this over I would appreciate it.

Sorry for not reviewing the patch before you push it...

In HEAD, I ran very simple test case:

1. enable track_commit_timestamp
2. start the server
3. run some transactions
4. execute pg_last_committed_xact() -- returns non-null values
5. shutdown the server with immdiate mode
6. restart the server -- crash recovery happens
7. execute pg_last_committed_xact()

The last call of pg_last_committed_xact() returns NULL values, which means
that the xid and timestamp information of the last committed transaction
disappeared by crash recovery. Isn't this a bug?

Regards,

--
Fujii Masao

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

#21Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Fujii Masao (#20)
hackersdocs
#22Fujii Masao
masao.fujii@gmail.com
In reply to: Alvaro Herrera (#21)
hackersdocs
#23Robert Haas
robertmhaas@gmail.com
In reply to: Fujii Masao (#22)
hackersdocs
#24Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Robert Haas (#23)
hackersdocs
#25Robert Haas
robertmhaas@gmail.com
In reply to: Alvaro Herrera (#24)
hackersdocs
#26Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#21)
hackersdocs