A suggestion:
Have initdb do a tar and gzip of the prior contents of PG_DATA, and leave the result in the newly initialized PG_DATA
under a standard name, e.g. $PG_DATA.old.
Maybe also issue a warning/informative message so that the installer is reminded to go back and recover any files that
are actually needed, or simply delete the .tar.gz file in order to recover the space.
Subject: Re: initdb and "exit_nicely"...
> Date: Thu, 18 May 2000 11:05:58 -0400
> From: Tom Lane <tgl@sss.pgh.pa.us>
> To: "Len Morgan" <len-morgan@crcom.net>
> CC: pgsql-general@hub.org
> References: <002001bfc0be$fdbe7560$0908a8c0@H233.bstx.cc>
>
> "Len Morgan" <len-morgan@crcom.net> writes:
> > The reason that IMHO this deserves a little consideration (i.e., doing it at
> > all rather than just saying "Don't store any files in PG_DATA") is that
> > RedHat based rpm installations create the postgres superuser account as part
> > of the process and set the home directory for this user to PG_DATA.
>
> To be blunt, that's *incredibly* brain dead. The contents of the PGDATA
> directory are way too critical to be the account's home directory. The
> correct fix for this is to change the way the RPM sets up the account.
>
> I don't think we are doing anyone a service if we tweak initdb in a way
> that will make it slightly safer to keep random files in PGDATA. You
> shouldn't do it anyway, and modifying initdb to make it look like you
> can will only increase the risk of people accidentally screwing up their
> installation.
>
> regards, tom lane