Re: pg_upgrade if 'postgres' database is dropped - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: pg_upgrade if 'postgres' database is dropped
Date
Msg-id 201111031803.pA3I30E24469@momjian.us
Whole thread Raw
In response to Re: pg_upgrade if 'postgres' database is dropped  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
Bruce Momjian wrote:
> I fixed this a different way.  I originally thought I could skip over
> the 'postgres' database in the new cluster if it didn't exist in the old
> cluster, but we have do things like check it is empty, so that was going
> to be awkward.
>
> It turns out there was only one place that expected a 1-1 mapping of old
> and new databases (file transfer), so I just modified that code to allow
> skipping a database in the new cluster that didn't exist in the old
> cluster.
>
> Attached patch applied.  This allows an upgrade if the 'postgres'
> database is missing from the old cluster.

OK, I thought some more and didn't like the way the code could loop off
the end of the new cluster without matching all the old cluster
database.

The attached, applied patches improves this.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +
diff --git a/contrib/pg_upgrade/relfilenode.c b/contrib/pg_upgrade/relfilenode.c
new file mode 100644
index 382588f..d67d01f
*** a/contrib/pg_upgrade/relfilenode.c
--- b/contrib/pg_upgrade/relfilenode.c
*************** transfer_all_new_dbs(DbInfoArr *old_db_a
*** 41,51 ****

      /* Scan the old cluster databases and transfer their files */
      for (old_dbnum = new_dbnum = 0;
!          old_dbnum < old_db_arr->ndbs && new_dbnum < new_db_arr->ndbs;
           old_dbnum++, new_dbnum++)
      {
!         DbInfo       *old_db = &old_db_arr->dbs[old_dbnum];
!         DbInfo       *new_db = &new_db_arr->dbs[new_dbnum];
          FileNameMap *mappings;
          int            n_maps;
          pageCnvCtx *pageConverter = NULL;
--- 41,50 ----

      /* Scan the old cluster databases and transfer their files */
      for (old_dbnum = new_dbnum = 0;
!          old_dbnum < old_db_arr->ndbs;
           old_dbnum++, new_dbnum++)
      {
!         DbInfo       *old_db = &old_db_arr->dbs[old_dbnum], *new_db;
          FileNameMap *mappings;
          int            n_maps;
          pageCnvCtx *pageConverter = NULL;
*************** transfer_all_new_dbs(DbInfoArr *old_db_a
*** 55,67 ****
           *    but not in the old, e.g. "postgres".  (The user might
           *    have removed the 'postgres' database from the old cluster.)
           */
!         while (strcmp(old_db->db_name, new_db->db_name) != 0 &&
!                new_dbnum < new_db_arr->ndbs)
!             new_db = &new_db_arr->dbs[++new_dbnum];

!         if (strcmp(old_db->db_name, new_db->db_name) != 0)
!             pg_log(PG_FATAL, "old and new databases have different names: old \"%s\", new \"%s\"\n",
!                    old_db->db_name, new_db->db_name);

          n_maps = 0;
          mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata,
--- 54,69 ----
           *    but not in the old, e.g. "postgres".  (The user might
           *    have removed the 'postgres' database from the old cluster.)
           */
!         for (; new_dbnum < new_db_arr->ndbs; new_dbnum++)
!         {
!             new_db = &new_db_arr->dbs[new_dbnum];
!             if (strcmp(old_db->db_name, new_db->db_name) == 0)
!                 break;
!         }

!         if (new_dbnum >= new_db_arr->ndbs)
!             pg_log(PG_FATAL, "old database \"%s\" not found in the new cluster\n",
!                    old_db->db_name);

          n_maps = 0;
          mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata,

pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: GiST for range types (was Re: Range Types - typo + NULL string constructor)
Next
From: Alvaro Herrera
Date:
Subject: foreign key locks, 2nd attempt