Forum OpenACS Q&A: error restoring a database backup to a different database

1) Create a working OpenACS 4.5 on PostGreSQL 7.2.3
2) Back up the database with
psql pg_dump -f /backup/openacs/openacs_prod_initial.dmp openacs-prod
3) create a new database with createdb openacs-pre
4) try to put the old backup in the new database with:
psql openacs-pre < openacs_prod_initial.dmp

Results:
You are now connected as new user postgres.
ERROR:  function plpgsql_call_handler already exists with same argument types
ERROR:  Language plpgsql already exists
You are now connected as new user nsadmin.
CREATE (~20 times)
ERROR:  Function 'tree_ancestor_keys(varbit, int4)' does not exist
        Unable to identify a function that satisfies the given argument types
        You may need to add explicit typecasts
ERROR:  Function 'tree_ancestor_keys(varbit, int4)' does not exist
        Unable to identify a function that satisfies the given argument types
        You may need to add explicit typecasts
The rest of the process looks normal.

This then produces a similar error in Aolserver:

[10/Jan/2003:11:38:05][20138.3076][-conn0-] Error: Ns_PgExec: result status: 7 message: ERROR:  Function 'tree_ancestor_keys(varbit)' does not exist

Any tips?

before you restore the DB, load packages/acs-kernel/sql/postgresql/postgresql.sql
I accidentally posted my reply over here:

https://openacs.org/forums/message-view?message_id=70767

I beg your pardon...

The advice is right but it's worth explaining the reason ...

pg_dump does an imperfect job of dumping stuff out in correct order.  Function definitions can be dumped after their first use and this is true, in particular, of our tree functions.  This is why loading the postgres.sql file first works (just ignore any dupe-definition errors you get afterwards).

Hi,

I am answering Ola's post on the other thread.  He was noting if the patch is still needed nowadays.  Based from my observation I never had to use the patch when I started to use PG 7.2.x.  But as always when restoring, its always a good practice to redirect stderr and stdout to a log file and grep that log file for errors.

Loading packages/acs-kernel/sql/postgresql/postgresql.sql into the newly created database before restoring the backup caused the backup to spew errors about pre-existing stuff, which I ignored.  It appears to work fine.  Thanks.

This is with 7.2.3; several restores worked fine with just a create and restore, and several needed the file pre-loaded.