Re: How ugly would this be? (ALTER DATABASE)

From: Greg Stark <stark(at)mit(dot)edu>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How ugly would this be? (ALTER DATABASE)
Date: 2014-10-25 19:00:33
Message-ID: CAM-w4HPCdRZ-sBhZU3ja-hjR83nWUh9i7U5DQ6BCjnhHXi+ohw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 24 Oct 2014 20:28, "Robert Haas" <robertmhaas(at)gmail(dot)com> wrote:
>
> You could perhaps try to create a command that would move a schema
> between two databases in the same cluster. It's fraught with
> practical difficulties because a single backend can't be connected to
> both databases at the same time, so how exactly do you make the
> required catalog changes all in a single transaction? But if you
> imagine that you have an infinite pool of top-notch PostgreSQL talent
> with unbounded time to work on this problem and no other, I bet
> somebody could engineer a solution.

I think the bigger problem is the dependent objects. Things like data types
which might exist in both databases but with different oids.

If you simplify the problem to only handle tables and indexes and only if
they only use system types and other objects then it seems doable but that
creates a lot of pitfalls for users.

I would do it in three steps more like pg_upgrade. 1) copy the schema to
the new database and note the new oids and relfilenodes. 2) copy or move
the data files over. 3) drop the old schema. Each of those can be done in
separate transactions or even backends -- the intermediate states just have
some empty tables in one of the schemas.

It's not clear to me what state the databases should be in during step 2
though. A simple lock would not be sufficient. Perhaps there needs to be
something like indisvalid for tables. That might be handy for pg_bulkload
as well.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2014-10-25 21:10:28 Re: [PATCH] Support for Array ELEMENT Foreign Keys
Previous Message Tom Lane 2014-10-25 18:52:36 Re: Getting rid of "accept incoming network connections" prompts on OS X