Forum OpenACS Q&A: Reloading a databasse

Collapse
Posted by Ken Chakiris on

Before implementing Don's tips on backing up the database, I tried to verify that the dumped database would reload properly. Hence I did first

pg_dump my_database > my_database_bkup.

Next I created a new database my_database_test and did

psql -d my_database_test -f  

Unfortunately I got a number of errors on the reload. By the way I did all of the above as nsadmin. Some of the errors seem to be due to the order in which the orginal dump took place. Some create table commands required functions (eg sysdate) to be already defined. Others I am not sure what produced the errors.

Are there some hints that I am missing to do the dump and reload properly?

Collapse
Posted by Ken Chakiris on

Sorry for typos. The command I used for the reload left off the file name. It should read

psql -d my_database_test -f my_database_bkup 
Collapse
Posted by Roberto Mello on
AFAIK there's a problem with pg_dump and it's been rewritten with the fixes but I don't think it has been released, maybe 7.0.3? I had that same problem too and what we discussed is on a thread here somewhere.
Collapse
Posted by Bob OConnor on

I think that the thread that Roberto was referring to is
https://openacs.org/forums/message-view?message_id=15419
that was titled "PostgreSQL dying".

Being able to do a backup (which I do daily using Don's Script) and Restore if necessary is important. I've been lucky so far and I'm not desperate because of a failure --- knock on real wood --- er... all I have that wood here at my desk is an old wooden pencil 😊 I've never done a restore and hopefully I will be able to try it soon while not under failure pressure. Further insights are appreciated.

TIA -Bob

Collapse
Posted by Babak Ashrafi on
Could you point to where Don's script is? Thanks. Will restoring be problematic until the new pg_dump is released from Postgres? we have had problems with restores (causing crashes of postgres and aolserver)
Collapse
Posted by Don Baccus on
The out-of-order problems you're seeing can be fixed by hand-editing the dump file, which is a major pain in the butt but one which will go  away with 7.1 or maybe 7.0.3 (? not sure if this includes the new version of pg_dump).

Doing a restore shouldn't break AOLserver, unless you're deleting and restoring the actual database being used by it.  So that's a mystery.  It clearly shouldn't break Postgres, either, and if you have real breakage you should submit a bug report to the Postgres development group complete with an offer to supply the dump file that breaks it.

Collapse
Posted by Ken Chakiris on

Here is some further data. I proceeded as before and I dumped the database to my_database_bkup. I broke the my_database_bkup file into 6 seperate files: load.1, load.2, load.3, load.4, load.5, and load.6.

The file load.1 has all the CREATE FUNCTION commands. The file load.2 has all the CREATE SEQUENCE and CREATE TABLE commands. The file load.3 has all the COPY commands. The file load.4 has all the index creation commands. File load.5 has all the CREATE CONSTRAINT TRIGGER commands. The remaining file load.6 has the CREATE RULE commands. With the exception of load.1 and load.2, which are reversed, this is the same order that the output appears in the dump file.

Loading load.1 through load.5 went fine with no errors. However, loading load.6 produced a number of errors. For example:

psql:load.6:9:ERROR: select rules target entry 7 has different size from attribute read_permission_p

This rule is called _RETgeneral_permissions_grid. Does anyone understand what is happening here?

Collapse
Posted by Ken Chakiris on
This is continuation of my last message.  I restarted the AOL server with appropriate changes to the ini file. It seems to be working fine even though the load.6 file produced errors upon loading into the database.  I checked a number of the administrative functions and they seem to be working. This still leaves the question why the ERROR messages and what purpose the error producting rules serve in the Open ACS system.
Collapse
Posted by Ken Chakiris on

Well folks I think I understand alot better what is wrong. Why the output of pg_dump can't loaded without hand editing. There are two basic problems.

The first one is the order that pg_dump dumps things in. This is not too hard to fix. I added a trace function to the pg_dump that adds comments like

-- From Trace: start dumpRules

From this it is easy to write a Perl script that rewrites the pg_dump output to put things in the order needed to recreate the database. Unfortunately there is a second problem. The output of the dumpRules function in pg_dump creates an output that cannot be loaded without errors. These rules are created originally from the views. So that a view named user_group_member_field_mapping should produce a rule named "_RETuser_group_member_field_mapping." There are two related bugs. The name of the rule is truncated when parsed during the creation of the view if it is too long. (e.g. "_RETuser_group_member_field_mapping." becomes "_RETuser_group_field_map") This produces an error when reloaded. The second problem is the implementation of the rule can be loaded as view but produces errors when loaded as is. My work around for this is a Perl script that modifies the output of dumpRules so that they become a combination of DROP TABLES and CREATE VIEWS instead. So for example:

DROP TABLE user_group_member_field_mapping;
CREATE VIEW user_group_member_field_mapping .... blah... blah ...blah;

The bottom line is that I can basically create a Perl script that takes the output of pg_dump and creates files that can be reloaded without errors. I am still testing it to see whether one gets back the same database.

Collapse
Posted by Deane Mathewson on
Did you end up creating a workable script for this Ken?  It would be so nice if I didn't have to write one...
Collapse
Posted by Ken Chakiris on
Yes I did. I will be glad to share it with you.  It requires some changes to the pg_dump code.  I haven't looked at it in weeks but I will do so and e-mail it to you. I assume that I can get your e-mail address from the OpenACS site.
Collapse
Posted by Robert Ezman on
There's an older thread which goes into this stuff... You can find it
<a href="/forums/message-view?message_id=17125">here</a>.
<br><br>
I guess you went a little further in your research about this.  I stopped at moving the plpgsql function
handler declaration to the top of the file.