agora inbox for pgsql-admin@postgresql.org  
help / color / mirror / Atom feed
pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found
3+ messages / 3 participants
[nested] [flat]

* pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found
@ 2026-08-12 10:50 Holger Jakobs <holger@jakobs.com>
  2026-08-12 15:14 ` Re: pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found Tom Lane <tgl@sss.pgh.pa.us>
  2026-08-13 12:37 ` Re: pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found Michael Banck <mbanck@gmx.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Holger Jakobs @ 2026-08-12 10:50 UTC (permalink / raw)
  To: PostgreSQL mailing list <pgsql-admin@lists.postgresql.org>

Dear Friends,

Today a pg_upgrade failed with this awkward message:

Finding the real data directory for the source cluster        ok
Finding the real data directory for the target cluster        sh: 1: 
(null)/postgres: not found

I checked the source code of pg_upgrade.c and thus options.c and found 
that the (null) above stems from an uninitialised variable called cmd, 
declared in line 433 of option.c

Line 468 reads:

     snprintf(cmd, sizeof(cmd), "\"%s/postgres\" -D \"%s\" -C 
data_directory",
              cluster->bindir, cluster->pgconfig);

Calling the postgres binary (from the package, didn't compile myself) 
works fine and gives me the correct real data directory:

     $ /usr/lib/postgresql/18/bin/postgres -D /etc/postgresql/18/main -C 
data_directory
     /var/lib/postgresql/18/main

So how come that cmd is NULL in line 468? I actually cannot find where 
the variable was given any content, so it's NULL. This generates the 
error message with "(null)/postgres not found"

Obviously, cmd should contain the path of the oldbin directory, which is 
to be derived from the path of the pg_upgrade being called. I didn't use 
the -B option because the documentation says that it's optional and will 
use the directory of pg_upgrade.

https://www.postgresql.org/docs/current/pgupgrade.html tells me:
|   -B| /|bindir|/
|   --new-bindir=|/|bindir
|/         the new PostgreSQL executable directory; default is the 
directory where pg_upgrade resides

Obviously, this doesn't work as described.

When giving the path to the new bin directory with -B, pg_upgrade works 
fine.

Please correct the code so that cmd gets initialised or alter the 
documentation making the option -B mandatory.

Kind Regards,

Holger


-- 

Holger Jakobs, Bergisch Gladbach, Germany

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

* Re: pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found
  2026-08-12 10:50 pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found Holger Jakobs <holger@jakobs.com>
@ 2026-08-12 15:14 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2026-08-12 15:14 UTC (permalink / raw)
  To: Holger Jakobs <holger@jakobs.com>; +Cc: pgsql-bugs@lists.postgresql.org

[ redirecting to pgsql-bugs ]

Holger Jakobs <holger@jakobs.com> writes:
> Dear Friends,
> Today a pg_upgrade failed with this awkward message:

> Finding the real data directory for the source cluster        ok
> Finding the real data directory for the target cluster        sh: 1: 
> (null)/postgres: not found

I can reproduce this if (1) I omit -B (and don't give PGBINNEW
either), and (2) the target -D directory is a config-only directory,
that is it contains postgresql.conf but not PG_VERSION.  Given (1),
pg_upgrade is supposed to assume that -B should be the directory
that it itself was executed from.  However, that is filled in by
setup(), which does not run till after adjust_data_dir(), which is
reaching the "Finding the real data directory" bit because of (2).
So we arrive there with cluster->bindir still NULL, and kaboom.

So the temporary workaround for Holger is to specify -B explicitly,
but somebody needs to rethink the order of initialization steps here.
Maybe just move that bit of setup() into parseCommandLine()?

It looks like this is an error of pretty long standing...

			regards, tom lane






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

* Re: pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found
  2026-08-12 10:50 pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found Holger Jakobs <holger@jakobs.com>
@ 2026-08-13 12:37 ` Michael Banck <mbanck@gmx.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Banck @ 2026-08-13 12:37 UTC (permalink / raw)
  To: Holger Jakobs <holger@jakobs.com>; +Cc: PostgreSQL mailing list <pgsql-admin@lists.postgresql.org>

Hi,

On Wed, Aug 12, 2026 at 12:50:57PM +0200, Holger Jakobs wrote:
> Today a pg_upgrade failed with this awkward message:
> 
> Finding the real data directory for the source cluster        ok
> Finding the real data directory for the target cluster        sh: 1:
> (null)/postgres: not found

What was the exact command line you used?

> Obviously, cmd should contain the path of the oldbin directory, which is to
> be derived from the path of the pg_upgrade being called. 

Are you saying you ran the 17 pg_update binary? I am not sure that is
supported/supposed to work, one should use the pg_upgrade binary from
the newer Postgres version (unless I misunderstood you).

Still, the error isn't great and should be improved / this case should
be caught earlier in pre-flight checks probably.


Michael






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


end of thread, other threads:[~2026-08-13 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-12 10:50 pg_upgrade from 17.10 to 18.4 on Ubuntu fails: Finding the real data directory for the target cluster sh: 1: (null)/postgres: not found Holger Jakobs <holger@jakobs.com>
2026-08-12 15:14 ` Tom Lane <tgl@sss.pgh.pa.us>
2026-08-13 12:37 ` Michael Banck <mbanck@gmx.net>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox