pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Remove the restriction that the relmap must be 512 bytes.
16+ messages / 6 participants
[nested] [flat]

Commits from this thread:
  2022-07-27 5f858dd3be  Bump catversion for commit d8cd0c6c95c0120168df93aae095df4e0682a08a.
* pgsql: Remove the restriction that the relmap must be 512 bytes.
@ 2022-07-26 19:10 Robert Haas <rhaas@postgresql.org>
  2022-07-27 04:34 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 2 replies; 16+ messages in thread

From: Robert Haas @ 2022-07-26 19:10 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove the restriction that the relmap must be 512 bytes.

Instead of relying on the ability to atomically overwrite the
entire relmap file in one shot, write a new one and durably
rename it into place. Removing the struct padding and the
calculation showing why the map is exactly 512 bytes, and change
the maximum number of entries to a nearby round number.

Patch by me, reviewed by Andres Freund and Dilip Kumar.

Discussion: http://postgr.es/m/CA+TgmoZq5%3DLWDK7kHaUbmWXxcaTuw_QwafgG9dr-BaPym_U8WQ%40mail.gmail.com
Discussion: http://postgr.es/m/CAFiTN-ttOXLX75k_WzRo9ar=VvxFhrHi+rJxns997F+yvkm==A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d8cd0c6c95c0120168df93aae095df4e0682a08a

Modified Files
--------------
doc/src/sgml/monitoring.sgml            |  4 +-
src/backend/utils/activity/wait_event.c |  4 +-
src/backend/utils/cache/relmapper.c     | 94 +++++++++++++++++++--------------
src/include/utils/wait_event.h          |  2 +-
4 files changed, 58 insertions(+), 46 deletions(-)



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
@ 2022-07-27 04:34 ` Michael Paquier <michael@paquier.xyz>
  2022-07-27 05:01   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  1 sibling, 1 reply; 16+ messages in thread

From: Michael Paquier @ 2022-07-27 04:34 UTC (permalink / raw)
  To: Robert Haas <rhaas@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org

Hi Robert,

On Tue, Jul 26, 2022 at 07:10:22PM +0000, Robert Haas wrote:
> Remove the restriction that the relmap must be 512 bytes.
> 
> Instead of relying on the ability to atomically overwrite the
> entire relmap file in one shot, write a new one and durably
> rename it into place. Removing the struct padding and the
> calculation showing why the map is exactly 512 bytes, and change
> the maximum number of entries to a nearby round number.
> 
> Patch by me, reviewed by Andres Freund and Dilip Kumar.
> 
> Discussion: http://postgr.es/m/CA+TgmoZq5%3DLWDK7kHaUbmWXxcaTuw_QwafgG9dr-BaPym_U8WQ%40mail.gmail.com
> Discussion: http://postgr.es/m/CAFiTN-ttOXLX75k_WzRo9ar=VvxFhrHi+rJxns997F+yvkm==A@mail.gmail.com

The CI on Windows is blowing up here and there after something that
looks to come from this commit, as of this backtrace:
00000000`007fe300 00000001`405c62dd     postgres!errfinish(
char * filename = 0x00000001`40bf1513 "fd.c",
int lineno = 0n756,
char * funcname = 0x00000001`40bf14e0 "durable_rename")+0x41b
[c:\cirrus\src\backend\utils\error\elog.c @ 683]
00000000`007fe360 00000001`4081647b     postgres!durable_rename(
char * oldfile = 0x00000000`007fe430 "base/16384/pg_filenode.map.tmp",
char * newfile = 0x00000000`007fe830 "base/16384/pg_filenode.map",
int elevel = 0n21)+0x22d [c:\cirrus\src\backend\storage\file\fd.c @
753]
00000000`007fe3b0 00000001`408166c9     postgres!write_relmap_file(
struct RelMapFile * newmap = 0x00000000`007fecb0,
bool write_wal = true,
bool send_sinval = true,
bool preserve_files = true,
unsigned int dbid = 0x4000,
unsigned int tsid = 0x67f,
char * dbpath = 0x00000000`0090b1c0 "base/16384")+0x38b
[c:\cirrus\src\backend\utils\cache\relmapper.c @ 971]

Here is one of them, kicked by the CF bot, but I have seen similar
crashes with some of my own things (see the txt file in crashlog, in a
manual VACUUM):
https://cirrus-ci.com/task/5240408958566400

Thanks,
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 04:34 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
@ 2022-07-27 05:01   ` Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 06:06     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Thomas Munro @ 2022-07-27 05:01 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Robert Haas <rhaas@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 4:35 PM Michael Paquier <michael@paquier.xyz> wrote:
> On Tue, Jul 26, 2022 at 07:10:22PM +0000, Robert Haas wrote:
> > Remove the restriction that the relmap must be 512 bytes.

> The CI on Windows is blowing up here and there after something that
> looks to come from this commit, as of this backtrace:
> 00000000`007fe300 00000001`405c62dd     postgres!errfinish(
> char * filename = 0x00000001`40bf1513 "fd.c",
> int lineno = 0n756,
> char * funcname = 0x00000001`40bf14e0 "durable_rename")+0x41b
> [c:\cirrus\src\backend\utils\error\elog.c @ 683]

And here's what the error looks like:

2022-07-26 19:38:04.321 GMT [8020][client backend]
[pg_regress/vacuum][8/349:4527] PANIC:  could not rename file
"global/pg_filenode.map.tmp" to "global/pg_filenode.map": Permission
denied

Someone else still has the old file open, so we can't rename the new
one to its name?  On Windows that should have gone through pgrename()
in dirmod.c, which would retry 100 times with a 100ms sleep between.
Since every backend reads that file (I added an elog() and saw it 2289
times during make check), I guess you can run out of luck.

/me thinks





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 04:34 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
  2022-07-27 05:01   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
@ 2022-07-27 06:06     ` Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 06:21       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Thomas Munro @ 2022-07-27 06:06 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Robert Haas <rhaas@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 5:01 PM Thomas Munro <thomas.munro@gmail.com> wrote:
> On Wed, Jul 27, 2022 at 4:35 PM Michael Paquier <michael@paquier.xyz> wrote:
> > On Tue, Jul 26, 2022 at 07:10:22PM +0000, Robert Haas wrote:
> > > Remove the restriction that the relmap must be 512 bytes.
>
> > The CI on Windows is blowing up here and there after something that
> > looks to come from this commit, as of this backtrace:
> > 00000000`007fe300 00000001`405c62dd     postgres!errfinish(
> > char * filename = 0x00000001`40bf1513 "fd.c",
> > int lineno = 0n756,
> > char * funcname = 0x00000001`40bf14e0 "durable_rename")+0x41b
> > [c:\cirrus\src\backend\utils\error\elog.c @ 683]
>
> And here's what the error looks like:
>
> 2022-07-26 19:38:04.321 GMT [8020][client backend]
> [pg_regress/vacuum][8/349:4527] PANIC:  could not rename file
> "global/pg_filenode.map.tmp" to "global/pg_filenode.map": Permission
> denied
>
> Someone else still has the old file open, so we can't rename the new
> one to its name?  On Windows that should have gone through pgrename()
> in dirmod.c, which would retry 100 times with a 100ms sleep between.
> Since every backend reads that file (I added an elog() and saw it 2289
> times during make check), I guess you can run out of luck.
>
> /me thinks

Maybe we just have to rearrange the locking slightly?  Something like
the attached.

Attachments:

0001-Fix-read_relmap_file-concurrency-on-Windows.patch (text/x-patch, 2.0K) download From c4f52c8cabb35d7db6d24681227146a195688c39 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.munro@gmail.com> Date: Wed, 27 Jul 2022 18:01:12 +1200 Subject: [PATCH] Fix read_relmap_file() concurrency on Windows. Commit d8cd0c6c introduced a file rename that could fail on Windows due to other backends reading an old file of the same name. Re-arrange the locking slightly to prevent that. Discussion: https://postgr.es/m/CA%2BhUKGLZtCTgp4NTWV-wGbR2Nyag71%3DEfYTKjDKnk%2BfkhuFMHw%40mail.gmail.com --- src/backend/utils/cache/relmapper.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c index 79e09181b6..4562a0ad6f 100644 --- a/src/backend/utils/cache/relmapper.c +++ b/src/backend/utils/cache/relmapper.c @@ -788,16 +788,6 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel) Assert(elevel >= ERROR); - /* Open the target file. */ - snprintf(mapfilename, sizeof(mapfilename), "%s/%s", dbpath, - RELMAPPER_FILENAME); - fd = OpenTransientFile(mapfilename, O_RDONLY | PG_BINARY); - if (fd < 0) - ereport(elevel, - (errcode_for_file_access(), - errmsg("could not open file \"%s\": %m", - mapfilename))); - /* * Grab the lock to prevent the file from being updated while we read it, * unless the caller is already holding the lock. If the file is updated @@ -808,6 +798,16 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel) if (!lock_held) LWLockAcquire(RelationMappingLock, LW_SHARED); + /* Open the target file. */ + snprintf(mapfilename, sizeof(mapfilename), "%s/%s", dbpath, + RELMAPPER_FILENAME); + fd = OpenTransientFile(mapfilename, O_RDONLY | PG_BINARY); + if (fd < 0) + ereport(elevel, + (errcode_for_file_access(), + errmsg("could not open file \"%s\": %m", + mapfilename))); + /* Now read the data. */ pgstat_report_wait_start(WAIT_EVENT_RELATION_MAP_READ); r = read(fd, map, sizeof(RelMapFile)); -- 2.35.1
^ permalink raw reply [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 04:34 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
  2022-07-27 05:01   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 06:06     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
@ 2022-07-27 06:21       ` Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 10:25         ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 16+ messages in thread

From: Thomas Munro @ 2022-07-27 06:21 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Robert Haas <rhaas@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 6:06 PM Thomas Munro <thomas.munro@gmail.com> wrote:
> On Wed, Jul 27, 2022 at 5:01 PM Thomas Munro <thomas.munro@gmail.com> wrote:
> > Someone else still has the old file open, so we can't rename the new
> > one to its name?  On Windows that should have gone through pgrename()
> > in dirmod.c, which would retry 100 times with a 100ms sleep between.
> > Since every backend reads that file (I added an elog() and saw it 2289
> > times during make check), I guess you can run out of luck.
> >
> > /me thinks
>
> Maybe we just have to rearrange the locking slightly?  Something like
> the attached.

Erm, let me try that again, this time with the CloseTransientFile()
also under the lock, so that we never have a file handle without a
lock.

Attachments:

v2-0001-Fix-read_relmap_file-concurrency-on-Windows.patch (text/x-patch, 2.6K) download From 3f2b3e0e81f4dcf69a658df35248a0dbaf638eaf Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.munro@gmail.com> Date: Wed, 27 Jul 2022 18:01:12 +1200 Subject: [PATCH v2] Fix read_relmap_file() concurrency on Windows. Commit d8cd0c6c introduced a file rename that could fail on Windows, probably due to other backends having an open file handle to the old file of the same name. Re-arrange the locking slightly to prevent that, by making sure the open() and close() run while we hold the lock. Discussion: https://postgr.es/m/CA%2BhUKGLZtCTgp4NTWV-wGbR2Nyag71%3DEfYTKjDKnk%2BfkhuFMHw%40mail.gmail.com --- src/backend/utils/cache/relmapper.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c index 79e09181b6..7dca3be723 100644 --- a/src/backend/utils/cache/relmapper.c +++ b/src/backend/utils/cache/relmapper.c @@ -788,16 +788,6 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel) Assert(elevel >= ERROR); - /* Open the target file. */ - snprintf(mapfilename, sizeof(mapfilename), "%s/%s", dbpath, - RELMAPPER_FILENAME); - fd = OpenTransientFile(mapfilename, O_RDONLY | PG_BINARY); - if (fd < 0) - ereport(elevel, - (errcode_for_file_access(), - errmsg("could not open file \"%s\": %m", - mapfilename))); - /* * Grab the lock to prevent the file from being updated while we read it, * unless the caller is already holding the lock. If the file is updated @@ -808,6 +798,16 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel) if (!lock_held) LWLockAcquire(RelationMappingLock, LW_SHARED); + /* Open the target file. */ + snprintf(mapfilename, sizeof(mapfilename), "%s/%s", dbpath, + RELMAPPER_FILENAME); + fd = OpenTransientFile(mapfilename, O_RDONLY | PG_BINARY); + if (fd < 0) + ereport(elevel, + (errcode_for_file_access(), + errmsg("could not open file \"%s\": %m", + mapfilename))); + /* Now read the data. */ pgstat_report_wait_start(WAIT_EVENT_RELATION_MAP_READ); r = read(fd, map, sizeof(RelMapFile)); @@ -825,15 +825,15 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel) } pgstat_report_wait_end(); - if (!lock_held) - LWLockRelease(RelationMappingLock); - if (CloseTransientFile(fd) != 0) ereport(elevel, (errcode_for_file_access(), errmsg("could not close file \"%s\": %m", mapfilename))); + if (!lock_held) + LWLockRelease(RelationMappingLock); + /* check for correct magic number, etc */ if (map->magic != RELMAPPER_FILEMAGIC || map->num_mappings < 0 || -- 2.35.1
^ permalink raw reply [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 04:34 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
  2022-07-27 05:01   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 06:06     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 06:21       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
@ 2022-07-27 10:25         ` Michael Paquier <michael@paquier.xyz>
  2022-07-27 15:20           ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Michael Paquier @ 2022-07-27 10:25 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Robert Haas <rhaas@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 06:21:07PM +1200, Thomas Munro wrote:
> Erm, let me try that again, this time with the CloseTransientFile()
> also under the lock, so that we never have a file handle without a
> lock.

Right.  The whole write_relmap_file() already happens while taking
RelationMappingLock, so that seems like a good idea for consistency at
the end (even if I remember that there is a patch floating around to
improve the concurrency of pgrename, which may become an easier move
now that we require Windows 10).

I have tested three runs and that was working here even if the
issue is sporadic, so more runs may be better to have more
confidence.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 04:34 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
  2022-07-27 05:01   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 06:06     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 06:21       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Thomas Munro <thomas.munro@gmail.com>
  2022-07-27 10:25         ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Michael Paquier <michael@paquier.xyz>
@ 2022-07-27 15:20           ` Robert Haas <robertmhaas@gmail.com>
  0 siblings, 0 replies; 16+ messages in thread

From: Robert Haas @ 2022-07-27 15:20 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Thomas Munro <thomas.munro@gmail.com>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 6:25 AM Michael Paquier <michael@paquier.xyz> wrote:
> Right.  The whole write_relmap_file() already happens while taking
> RelationMappingLock, so that seems like a good idea for consistency at
> the end (even if I remember that there is a patch floating around to
> improve the concurrency of pgrename, which may become an easier move
> now that we require Windows 10).
>
> I have tested three runs and that was working here even if the
> issue is sporadic, so more runs may be better to have more
> confidence.

OK, I committed Thomas's patch, after taking the liberty of adding an
explanatory comment.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
@ 2022-07-27 17:19 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  1 sibling, 1 reply; 16+ messages in thread

From: Alvaro Herrera @ 2022-07-27 17:19 UTC (permalink / raw)
  To: Robert Haas <rhaas@postgresql.org>; +Cc: pgsql-hackers@lists.postgresql.org

On 2022-Jul-26, Robert Haas wrote:

> Remove the restriction that the relmap must be 512 bytes.
> 
> Instead of relying on the ability to atomically overwrite the
> entire relmap file in one shot, write a new one and durably
> rename it into place. Removing the struct padding and the
> calculation showing why the map is exactly 512 bytes, and change
> the maximum number of entries to a nearby round number.

Another thing that seems to have happened here is that catversion ought
to have been touched and wasn't.  Trying to start a cluster that was
initdb'd with the previous code enters an infinite loop that dies each
time with

2022-07-27 19:17:27.589 CEST [2516547] LOG:  database system is ready to accept connections
2022-07-27 19:17:27.589 CEST [2516730] FATAL:  could not read file "global/pg_filenode.map": read 512 of 524
2022-07-27 19:17:27.589 CEST [2516731] FATAL:  could not read file "global/pg_filenode.map": read 512 of 524
2022-07-27 19:17:27.589 CEST [2516547] LOG:  autovacuum launcher process (PID 2516730) exited with exit code 1
2022-07-27 19:17:27.589 CEST [2516547] LOG:  terminating any other active server processes

Perhaps we should still do a catversion bump now, since one hasn't
happened since the commit.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"El número de instalaciones de UNIX se ha elevado a 10,
y se espera que este número aumente" (UPM, 1972)





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2022-07-27 17:38   ` Robert Haas <robertmhaas@gmail.com>
  2022-07-27 17:42     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 16+ messages in thread

From: Robert Haas @ 2022-07-27 17:38 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 1:19 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
> Another thing that seems to have happened here is that catversion ought
> to have been touched and wasn't.  Trying to start a cluster that was
> initdb'd with the previous code enters an infinite loop that dies each
> time with
>
> 2022-07-27 19:17:27.589 CEST [2516547] LOG:  database system is ready to accept connections
> 2022-07-27 19:17:27.589 CEST [2516730] FATAL:  could not read file "global/pg_filenode.map": read 512 of 524
> 2022-07-27 19:17:27.589 CEST [2516731] FATAL:  could not read file "global/pg_filenode.map": read 512 of 524
> 2022-07-27 19:17:27.589 CEST [2516547] LOG:  autovacuum launcher process (PID 2516730) exited with exit code 1
> 2022-07-27 19:17:27.589 CEST [2516547] LOG:  terminating any other active server processes
>
> Perhaps we should still do a catversion bump now, since one hasn't
> happened since the commit.

Hmm, interesting. I didn't think about bumping catversion because I
didn't change anything in the catalogs. I did think about changing the
magic number for the file at one point, but unlike some of our other
constants, there's no indication that this one is intended to be used
as a version number. But in retrospect it would have been good to
change something somewhere. If you want me to bump catversion now, I
can. If you or someone else wants to do it, that's also fine.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
@ 2022-07-27 17:42     ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 18:13       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Tom Lane @ 2022-07-27 17:42 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Robert Haas <robertmhaas@gmail.com> writes:
> On Wed, Jul 27, 2022 at 1:19 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>> Another thing that seems to have happened here is that catversion ought
>> to have been touched and wasn't.

> Hmm, interesting. I didn't think about bumping catversion because I
> didn't change anything in the catalogs. I did think about changing the
> magic number for the file at one point, but unlike some of our other
> constants, there's no indication that this one is intended to be used
> as a version number. But in retrospect it would have been good to
> change something somewhere. If you want me to bump catversion now, I
> can. If you or someone else wants to do it, that's also fine.

If there's a magic number, then I'd (a) change that and (b) adjust
whatever comments led you to think you shouldn't.  Bumping catversion
is a good fallback choice when there's not any more-proximate version
indicator, but here there is.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 17:42     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-07-27 18:13       ` Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:24         ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Robert Haas @ 2022-07-27 18:13 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 1:42 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> If there's a magic number, then I'd (a) change that and (b) adjust
> whatever comments led you to think you shouldn't.  Bumping catversion
> is a good fallback choice when there's not any more-proximate version
> indicator, but here there is.

Maybe I just got cold feet because it doesn't ever have seem to have
been changed before, because the definition says:

#define RELMAPPER_FILEMAGIC     0x592717    /* version ID value */

And the fact that "version" is in there sure makes it seem like a
version number, now that I look again.

I'll add 1 to the value.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 17:42     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 18:13       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
@ 2022-07-27 18:24         ` Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:45           ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 1 reply; 16+ messages in thread

From: Robert Haas @ 2022-07-27 18:24 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 2:13 PM Robert Haas <robertmhaas@gmail.com> wrote:
> On Wed, Jul 27, 2022 at 1:42 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > If there's a magic number, then I'd (a) change that and (b) adjust
> > whatever comments led you to think you shouldn't.  Bumping catversion
> > is a good fallback choice when there's not any more-proximate version
> > indicator, but here there is.
>
> Maybe I just got cold feet because it doesn't ever have seem to have
> been changed before, because the definition says:
>
> #define RELMAPPER_FILEMAGIC     0x592717    /* version ID value */
>
> And the fact that "version" is in there sure makes it seem like a
> version number, now that I look again.
>
> I'll add 1 to the value.

Hmm, but that doesn't actually produce nice behavior. It just goes
into an infinite loop, like this:

2022-07-27 14:21:12.826 EDT [32849] LOG:  database system was
interrupted; last known up at 2022-07-27 14:21:12 EDT
2022-07-27 14:21:12.860 EDT [32849] LOG:  database system was not
properly shut down; automatic recovery in progress
2022-07-27 14:21:12.861 EDT [32849] LOG:  invalid record length at
0/14B3BB8: wanted 24, got 0
2022-07-27 14:21:12.861 EDT [32849] LOG:  redo is not required
2022-07-27 14:21:12.864 EDT [32850] LOG:  checkpoint starting:
end-of-recovery immediate wait
2022-07-27 14:21:12.865 EDT [32850] LOG:  checkpoint complete: wrote 3
buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled;
write=0.001 s, sync=0.001 s, total=0.002 s; sync files=2,
longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB;
lsn=0/14B3BB8, redo lsn=0/14B3BB8
2022-07-27 14:21:12.868 EDT [31930] LOG:  database system is ready to
accept connections
2022-07-27 14:21:12.869 EDT [32853] FATAL:  relation mapping file
"global/pg_filenode.map" contains invalid data
2022-07-27 14:21:12.869 EDT [32854] FATAL:  relation mapping file
"global/pg_filenode.map" contains invalid data
2022-07-27 14:21:12.870 EDT [31930] LOG:  autovacuum launcher process
(PID 32853) exited with exit code 1
2022-07-27 14:21:12.870 EDT [31930] LOG:  terminating any other active
server processes
2022-07-27 14:21:12.870 EDT [31930] LOG:  background worker "logical
replication launcher" (PID 32854) exited with exit code 1
2022-07-27 14:21:12.871 EDT [31930] LOG:  all server processes
terminated; reinitializing

While I agree that changing a version identifier that is more closely
related to what got changed is better than changing a generic one, I
think people won't like an infinite loop that spews messages into the
log at top speed as a way of telling them about the problem.

So now I'm back to being unsure what to do here.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 17:42     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 18:13       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:24         ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
@ 2022-07-27 18:45           ` Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 19:17             ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 16+ messages in thread

From: Alvaro Herrera @ 2022-07-27 18:45 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On 2022-Jul-27, Robert Haas wrote:

> Hmm, but that doesn't actually produce nice behavior. It just goes
> into an infinite loop, like this:

> 2022-07-27 14:21:12.869 EDT [32853] FATAL:  relation mapping file
> "global/pg_filenode.map" contains invalid data

This seems almost identical what happens without the version number
change, so I wouldn't call it much of an improvement.

> While I agree that changing a version identifier that is more closely
> related to what got changed is better than changing a generic one, I
> think people won't like an infinite loop that spews messages into the
> log at top speed as a way of telling them about the problem.
> 
> So now I'm back to being unsure what to do here.

I vote to go for the catversion bump for now.  

Maybe it's possible to patch the relmapper code afterwards, so that if a
version mismatch is detected the server is stopped with a reasonable
message.  An hypothetical improvement would be to keep the code to read
the old version and upgrade the file automatically, but given the number
of times that this file has changed, it's likely pointless effort.

Therefore, my proposal is to add a comment next to the struct definition
suggesting to bump catversion and call it a day.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 17:42     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 18:13       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:24         ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:45           ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2022-07-27 19:17             ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 19:39               ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Tom Lane @ 2022-07-27 19:17 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: Robert Haas <robertmhaas@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
>> Hmm, but that doesn't actually produce nice behavior. It just goes
>> into an infinite loop, like this:
>> So now I'm back to being unsure what to do here.

> I vote to go for the catversion bump for now.  

What this is showing us is that any form of corruption in the relmapper
file causes very unpleasant behavior.  We probably had better do something
about that, independently of this issue.

In the meantime, I still think bumping the file magic number is a better
answer.  It won't make the behavior any worse for un-updated code than
it is already.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 17:42     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 18:13       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:24         ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:45           ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 19:17             ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-07-27 19:39               ` Robert Haas <robertmhaas@gmail.com>
  2022-07-27 20:05                 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 16+ messages in thread

From: Robert Haas @ 2022-07-27 19:39 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Wed, Jul 27, 2022 at 3:17 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> >> Hmm, but that doesn't actually produce nice behavior. It just goes
> >> into an infinite loop, like this:
> >> So now I'm back to being unsure what to do here.
>
> > I vote to go for the catversion bump for now.
>
> What this is showing us is that any form of corruption in the relmapper
> file causes very unpleasant behavior.  We probably had better do something
> about that, independently of this issue.

I'm not sure how important that is, but it certainly wouldn't hurt.

> In the meantime, I still think bumping the file magic number is a better
> answer.  It won't make the behavior any worse for un-updated code than
> it is already.

But it also won't make it any better, so why even bother? The goal of
catversion bumps is to replace crashes or unpredictable misbehavior
with a nice error message that tells you exactly what the problem is.
Here we'd just be replacing an infinite series of crashes with an
infinite series of crashes with a slightly different error message.
It's probably worth comparing those error messages:

FATAL:  could not read file "global/pg_filenode.map": read 512 of 524
FATAL:  relation mapping file "global/pg_filenode.map" contains invalid data

The first message is what you get now. The second message is what you
get with the proposed change to the magic number. I would argue that
the second message is actually worse than the first one, because the
first one actually gives you some hint what the problem is, whereas
the second one really just says that an unspecified bad thing
happened.

In short, I think Alvaro's idea is unprincipled but solves the problem
of making it clear that a new initdb is required. Your idea is
principled but does not solve any problem.

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
  2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
  2022-07-27 17:19 ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 17:38   ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 17:42     ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 18:13       ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:24         ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
  2022-07-27 18:45           ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Alvaro Herrera <alvherre@alvh.no-ip.org>
  2022-07-27 19:17             ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Tom Lane <tgl@sss.pgh.pa.us>
  2022-07-27 19:39               ` Re: pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <robertmhaas@gmail.com>
@ 2022-07-27 20:05                 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 16+ messages in thread

From: Tom Lane @ 2022-07-27 20:05 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Robert Haas <robertmhaas@gmail.com> writes:
> In short, I think Alvaro's idea is unprincipled but solves the problem
> of making it clear that a new initdb is required. Your idea is
> principled but does not solve any problem.

[ shrug... ] Fair enough.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 16+ messages in thread


end of thread, other threads:[~2022-07-27 20:05 UTC | newest]

Thread overview: 16+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-07-26 19:10 pgsql: Remove the restriction that the relmap must be 512 bytes. Robert Haas <rhaas@postgresql.org>
2022-07-27 04:34 ` Michael Paquier <michael@paquier.xyz>
2022-07-27 05:01   ` Thomas Munro <thomas.munro@gmail.com>
2022-07-27 06:06     ` Thomas Munro <thomas.munro@gmail.com>
2022-07-27 06:21       ` Thomas Munro <thomas.munro@gmail.com>
2022-07-27 10:25         ` Michael Paquier <michael@paquier.xyz>
2022-07-27 15:20           ` Robert Haas <robertmhaas@gmail.com>
2022-07-27 17:19 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-07-27 17:38   ` Robert Haas <robertmhaas@gmail.com>
2022-07-27 17:42     ` Tom Lane <tgl@sss.pgh.pa.us>
2022-07-27 18:13       ` Robert Haas <robertmhaas@gmail.com>
2022-07-27 18:24         ` Robert Haas <robertmhaas@gmail.com>
2022-07-27 18:45           ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-07-27 19:17             ` Tom Lane <tgl@sss.pgh.pa.us>
2022-07-27 19:39               ` Robert Haas <robertmhaas@gmail.com>
2022-07-27 20:05                 ` Tom Lane <tgl@sss.pgh.pa.us>

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