Latest version of Hot Standby patch

Started by Simon Riggsover 17 years ago42 messageshackers
Jump to latest
#1Simon Riggs
simon@2ndQuadrant.com

http://wiki.postgresql.org/wiki/Hot_Standby

now contains a link to latest version of this patch. This is still at
"v5", just brought forward to CVS HEAD.

I will be doing further work on the patch from here and will reply to
this post each time I submit a new version.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#2Simon Riggs
simon@2ndQuadrant.com
In reply to: Simon Riggs (#1)
Re: Latest version of Hot Standby patch

On Wed, 2008-12-17 at 15:21 +0000, Simon Riggs wrote:

http://wiki.postgresql.org/wiki/Hot_Standby

now contains a link to latest version of this patch. This is still at
"v5", just brought forward to CVS HEAD.

I will be doing further work on the patch from here and will reply to
this post each time I submit a new version.

New version (already!) v5 - this time slightly broken down to aid review

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#3Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#2)
Re: Latest version of Hot Standby patch

Can't we use the existing backendid in place of the slot id?

(sorry if this has been discussed already; can't remember)

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

#4Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#3)
Re: Latest version of Hot Standby patch

On Thu, 2008-12-18 at 15:13 +0200, Heikki Linnakangas wrote:

Can't we use the existing backendid in place of the slot id?

(sorry if this has been discussed already; can't remember)

Exactly the sort of question we need, but unfortunately I'm a little
hazy, but I just woke up some maybe some coffee will change that answer
later.

They're certainly related and I did try it initially. SlotId was not
present in early versions of the patch up to 13 Oct, though backendId
was.

IIRC there were a couple of reasons

* corner case behaviour of backendids - bgwriter writes checkpoint WAL
records. Has no backendid, but needs a slotid (possibly others)

* slotids are assigned once and never changed, so allowing them to be
used as array lookups directly

I think it would be possible to use slotids as backendids, but not the
other way around. Anyway, seemed like a great way to induce bugs into
the sinval code, so I didn't try too hard to make them identical.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#5Simon Riggs
simon@2ndQuadrant.com
In reply to: Simon Riggs (#1)
Re: Latest version of Hot Standby patch

On Wed, 2008-12-17 at 15:21 +0000, Simon Riggs wrote:

http://wiki.postgresql.org/wiki/Hot_Standby

now contains a link to latest version of this patch. This is still at
"v5", just brought forward to CVS HEAD.

I will be doing further work on the patch from here and will reply to
this post each time I submit a new version.

New version: patch apply fixed, doc typos corrected

First half of Wiki docs checked and updated to explain User and Admin
Overview exactly as currently implemented.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#6Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#4)
Re: Latest version of Hot Standby patch

Simon Riggs wrote:

* corner case behaviour of backendids - bgwriter writes checkpoint WAL
records. Has no backendid, but needs a slotid (possibly others)

Why does bgwriter need a slotid? It doesn't run any transactions.

* slotids are assigned once and never changed, so allowing them to be
used as array lookups directly

So are backend ids.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

#7Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#6)
Re: Latest version of Hot Standby patch

On Fri, 2008-12-19 at 10:59 +0200, Heikki Linnakangas wrote:

Simon Riggs wrote:

* corner case behaviour of backendids - bgwriter writes checkpoint WAL
records. Has no backendid, but needs a slotid (possibly others)

Why does bgwriter need a slotid? It doesn't run any transactions.

* slotids are assigned once and never changed, so allowing them to be
used as array lookups directly

So are backend ids.

I'm a little hazy, to be sure. I'm pretty sure there was a blocker, but
if I cannot recall it we should assume it doesn't exist.

Where are you going with the thought? Remove slotId from each proc and
then use backendId to identify the recovery proc?

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#8Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#7)
Re: Latest version of Hot Standby patch

Simon Riggs wrote:

On Fri, 2008-12-19 at 10:59 +0200, Heikki Linnakangas wrote:

Simon Riggs wrote:

* corner case behaviour of backendids - bgwriter writes checkpoint WAL
records. Has no backendid, but needs a slotid (possibly others)

Why does bgwriter need a slotid? It doesn't run any transactions.

* slotids are assigned once and never changed, so allowing them to be
used as array lookups directly

So are backend ids.

I'm a little hazy, to be sure. I'm pretty sure there was a blocker, but
if I cannot recall it we should assume it doesn't exist.

Where are you going with the thought? Remove slotId from each proc and
then use backendId to identify the recovery proc?

Yep.

Well, to be honest, I don't much like the whole notion of tracking the
slots. I think we should just rely on the XLOG_RECOVERY_END records to
purge stale PGPROC entries, belonging to backends that died without
writing an abort record.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

#9Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Heikki Linnakangas (#8)
Re: Latest version of Hot Standby patch

Heikki Linnakangas wrote:

Well, to be honest, I don't much like the whole notion of tracking the
slots. I think we should just rely on the XLOG_RECOVERY_END records to
purge stale PGPROC entries, belonging to backends that died without
writing an abort record.

Sorry, I meant XLOG_XACT_RUNNING_XACTS, not XLOG_RECOVERY_END.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

#10Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#9)
Re: Latest version of Hot Standby patch

On Fri, 2008-12-19 at 14:00 +0200, Heikki Linnakangas wrote:

Heikki Linnakangas wrote:

Well, to be honest, I don't much like the whole notion of tracking the
slots. I think we should just rely on the XLOG_RECOVERY_END records to
purge stale PGPROC entries, belonging to backends that died without
writing an abort record.

Sorry, I meant XLOG_XACT_RUNNING_XACTS, not XLOG_RECOVERY_END.

OK, previous response aborted, but the problem is fairly similar.

If we just assign a recovery proc to each new transaction started then

* we would need an expandable number of recovery procs to cope with the
fact that we have more potentially emulated transactions than procs.
This info needs to be in shared memory, so however many you allocate, it
can still run out. Then what do you do? PANIC recovery and permanently
fail? Kick off all queries until a XLOG_XACT_RUNNING_XACTS arrives?

* there would be no direct mapping between the commit record and the
proc, so each commit would need to scan the whole proc array to get the
correct proc (which is potentially getting bigger and bigger because of
the first point)

The slotid (or backendid) is essential to keeping the number of emulated
transactions bounded at all times. I don't see that it costs much, if
anything and the resulting code is at least as simple as the
alternatives.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#11Simon Riggs
simon@2ndQuadrant.com
In reply to: Simon Riggs (#1)
Re: Latest version of Hot Standby patch

On Wed, 2008-12-17 at 15:21 +0000, Simon Riggs wrote:

http://wiki.postgresql.org/wiki/Hot_Standby

now contains a link to latest version of this patch.

v6 of Hot Standby now uploaded to Wiki (link above), with these changes:

* Must ignore_killed_tuples and never kill_prior_tuple during index
scans in recovery (v6)
* XLOG_BTREE_DELETE records handled correctly (v6)
* btree VACUUM code - must scan every block of index (v6)
* BEGIN TRANSACTION READ WRITE should throw error (v6)

New test cycle starting with this patch over next few days.

Work continues on other items.

Happy New Year everyone,

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#12Guillaume Lelarge
guillaume@lelarge.info
In reply to: Simon Riggs (#11)
Re: Latest version of Hot Standby patch

Simon Riggs a écrit :

On Wed, 2008-12-17 at 15:21 +0000, Simon Riggs wrote:

http://wiki.postgresql.org/wiki/Hot_Standby

now contains a link to latest version of this patch.

v6 of Hot Standby now uploaded to Wiki (link above), with these changes:

* Must ignore_killed_tuples and never kill_prior_tuple during index
scans in recovery (v6)
* XLOG_BTREE_DELETE records handled correctly (v6)
* btree VACUUM code - must scan every block of index (v6)
* BEGIN TRANSACTION READ WRITE should throw error (v6)

New test cycle starting with this patch over next few days.

I use latest CVS version. I tried to apply the patches and I have the
following error :

./hs.apply.sh: line 4: hs.prevent.v5.patch

I think you forgot to update the script. hs.prevent.v5.patch doesn't
exist in the tar file but hs.prevent.v6.patch does. Not sure we really
need this new file because I have a compilation error if I use the new
one. I don't have this error when I don't use the hs.prevent.v6.patch
file. Compilation error is :

utility.c: In function ‘ProcessUtility’:

utility.c:292: erreur: expected ‘)’ before ‘{’ token

utility.c:306: erreur: expected expression before ‘}’ token

And one file didn't want to get patched :

patching file src/include/catalog/pg_proc.h
Hunk #1 FAILED at 3223.
1 out of 1 hunk FAILED -- saving rejects to file
src/include/catalog/pg_proc.h.rej

Not sure why. I did patch it manually, but I still have my compilation
error.

Regards.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

#13Simon Riggs
simon@2ndQuadrant.com
In reply to: Guillaume Lelarge (#12)
Re: Latest version of Hot Standby patch

On Fri, 2009-01-02 at 11:02 +0100, Guillaume Lelarge wrote:

Simon Riggs a écrit :

On Wed, 2008-12-17 at 15:21 +0000, Simon Riggs wrote:

http://wiki.postgresql.org/wiki/Hot_Standby

now contains a link to latest version of this patch.

v6 of Hot Standby now uploaded to Wiki (link above), with these changes:

* Must ignore_killed_tuples and never kill_prior_tuple during index
scans in recovery (v6)
* XLOG_BTREE_DELETE records handled correctly (v6)
* btree VACUUM code - must scan every block of index (v6)
* BEGIN TRANSACTION READ WRITE should throw error (v6)

New test cycle starting with this patch over next few days.

I use latest CVS version. I tried to apply the patches and I have the
following error :

Thanks, will fix.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#14Simon Riggs
simon@2ndQuadrant.com
In reply to: Simon Riggs (#13)
Re: Latest version of Hot Standby patch

On Fri, 2009-01-02 at 17:35 +0000, Simon Riggs wrote:

I use latest CVS version. I tried to apply the patches and I have the
following error :

Thanks, will fix.

Fixed various bit rots and re-packaged. v6a now up, v6 unlinked.

Thanks,

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#15Guillaume Lelarge
guillaume@lelarge.info
In reply to: Simon Riggs (#14)
Re: Latest version of Hot Standby patch

Simon Riggs a �crit :

On Fri, 2009-01-02 at 17:35 +0000, Simon Riggs wrote:

I use latest CVS version. I tried to apply the patches and I have the
following error :

Thanks, will fix.

Fixed various bit rots and re-packaged. v6a now up, v6 unlinked.

Thanks. I only did a few checks and it worked great for me. I will try
to put some more time on it.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

#16Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Simon Riggs (#11)
Re: Latest version of Hot Standby patch: unexpected error querying standby

Simon Riggs wrote:

On Wed, 2008-12-17 at 15:21 +0000, Simon Riggs wrote:

http://wiki.postgresql.org/wiki/Hot_Standby

now contains a link to latest version of this patch.

v6 of Hot Standby now uploaded to Wiki (link above), with these changes:

* Must ignore_killed_tuples and never kill_prior_tuple during index
scans in recovery (v6)
* XLOG_BTREE_DELETE records handled correctly (v6)
* btree VACUUM code - must scan every block of index (v6)
* BEGIN TRANSACTION READ WRITE should throw error (v6)

New test cycle starting with this patch over next few days.

Work continues on other items.

Happy New Year everyone,

I'm running some tests on v6a. The setup is:

- install master, setup standby as usual, start standby
- create database bench on master
- initialize pgbench dataset size 100 on master
- start 4 clients doing 500000 transactions each.

After about 100000 transactions have been processed on the master, query
the standby:

bench=# \d history
Table "public.history"
Column | Type | Modifiers
--------+-----------------------------+-----------
tid | integer |
bid | integer |
aid | integer |
delta | integer |
mtime | timestamp without time zone |
filler | character(22) |

bench=# select now(),count(*) from history;
ERROR: could not open relation base/16384/16394: No such file or directory

regards

Mark

#17Simon Riggs
simon@2ndQuadrant.com
In reply to: Mark Kirkwood (#16)
Re: Latest version of Hot Standby patch: unexpected error querying standby

On Sun, 2009-01-04 at 21:03 +1300, Mark Kirkwood wrote:

bench=# select now(),count(*) from history;
ERROR: could not open relation base/16384/16394: No such file or
directory

Thanks for the report.

I'm attempting to recreate now.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#18Simon Riggs
simon@2ndQuadrant.com
In reply to: Mark Kirkwood (#16)
Re: Latest version of Hot Standby patch: unexpected error querying standby

On Sun, 2009-01-04 at 21:03 +1300, Mark Kirkwood wrote:

bench=# \d history
Table "public.history"
Column | Type | Modifiers
--------+-----------------------------+-----------
tid | integer |
bid | integer |
aid | integer |
delta | integer |
mtime | timestamp without time zone |
filler | character(22) |

bench=# select now(),count(*) from history;
ERROR: could not open relation base/16384/16394: No such file or
directory

From my recreating your test case, the oids are consistent with the

History table. So the cache looks good.

md.c should be cacheing the file descriptor so the second use of the
file should not be reopening it. I've not touched smgr/md so a missing
file error is a surprise.

I wonder if this is an error associated with large file handling and
file forks? Smells like an FSM or VM error.

Is the file actually missing? i.e. ls -l mydatadir/base/16384/16394*

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#19Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Simon Riggs (#18)
Re: Latest version of Hot Standby patch: unexpected error querying standby

Simon Riggs wrote:

On Sun, 2009-01-04 at 21:03 +1300, Mark Kirkwood wrote:

bench=# \d history
Table "public.history"
Column | Type | Modifiers
--------+-----------------------------+-----------
tid | integer |
bid | integer |
aid | integer |
delta | integer |
mtime | timestamp without time zone |
filler | character(22) |

bench=# select now(),count(*) from history;
ERROR: could not open relation base/16384/16394: No such file or
directory

From my recreating your test case, the oids are consistent with the

History table. So the cache looks good.

md.c should be cacheing the file descriptor so the second use of the
file should not be reopening it. I've not touched smgr/md so a missing
file error is a surprise.

I wonder if this is an error associated with large file handling and
file forks? Smells like an FSM or VM error.

Is the file actually missing? i.e. ls -l mydatadir/base/16384/16394*

Yeah -
$ ls -l $PGDATA/base/16384/16394*
ls: /data0/pgslave/8.4/base/16384/16394*: No such file or directory

regards

Mark

#20Mark Kirkwood
mark.kirkwood@catalyst.net.nz
In reply to: Mark Kirkwood (#19)
Re: Latest version of Hot Standby patch: unexpected error querying standby

Mark Kirkwood wrote:

Simon Riggs wrote:

On Sun, 2009-01-04 at 21:03 +1300, Mark Kirkwood wrote:

bench=# \d history
Table "public.history"
Column | Type | Modifiers
--------+-----------------------------+-----------
tid | integer |
bid | integer |
aid | integer |
delta | integer |
mtime | timestamp without time zone |
filler | character(22) |

bench=# select now(),count(*) from history;
ERROR: could not open relation base/16384/16394: No such file or
directory

From my recreating your test case, the oids are consistent with the

History table. So the cache looks good.

md.c should be cacheing the file descriptor so the second use of the
file should not be reopening it. I've not touched smgr/md so a missing
file error is a surprise.

I wonder if this is an error associated with large file handling and
file forks? Smells like an FSM or VM error.

Is the file actually missing? i.e. ls -l mydatadir/base/16384/16394*

Yeah -
$ ls -l $PGDATA/base/16384/16394*
ls: /data0/pgslave/8.4/base/16384/16394*: No such file or directory

This might be useful:

the other tables in the dataset (accounts, branches, tellers) all
behave as expected:

bench=# select now(),count(*) from branches;
now | count
-------------------------------+-------
2009-01-04 22:17:00.298597+13 | 100
(1 row)

I'm guessing something tied up with the fact that history has no rows to
start with...

#21Simon Riggs
simon@2ndQuadrant.com
In reply to: Mark Kirkwood (#19)
#22Simon Riggs
simon@2ndQuadrant.com
In reply to: Mark Kirkwood (#20)
#23Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#22)
#24Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Heikki Linnakangas (#23)
#25Bruce Momjian
bruce@momjian.us
In reply to: Heikki Linnakangas (#24)
#26Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#11)
#27Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#26)
#28Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#11)
#29Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#28)
#30Simon Riggs
simon@2ndQuadrant.com
In reply to: Simon Riggs (#1)
#31Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#30)
#32Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#31)
#33Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#32)
#34Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#33)
#35Simon Riggs
simon@2ndQuadrant.com
In reply to: Simon Riggs (#34)
#36Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#35)
#37Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#28)
#38Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#36)
#39Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#31)
#40Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#28)
#41Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Simon Riggs (#40)
#42Simon Riggs
simon@2ndQuadrant.com
In reply to: Heikki Linnakangas (#41)