Upgrade to Drupal 6.x from 4.x doesn't allow you to post anymore? Content gone?

I recently upgraded a couple sites using Drupal 4.7 to 6.20. The process was fairly straight forward except for a few things.

The upgrade from 4x to 5x went smoothly.
The upgrade from 5.23 to 6.20 was a disaster.

You have to start with a fresh install of 6.20. If you use your 5.23 directory it will fail.
You have to remove the database connection line in settings.php or 6.20 will assume the database works, and the existing 5.x database schema will fail.

After struggling with that, I managed to get a mirror up and running. I ran through the procedure one more time, and figured I was ready to deploy. I took down the sites, ran through the procedures, and violla! everything seemed like it worked. UNTIL....

I tried to post content. The post fail, which was bad enough, but then all the content seemed to be gone! For some reason, and it took some digging, the "node_access" table was empty. What happened? I looked at the logs and a bunch of queries failed. What happened?

The first step was to fix the site so people could view the content.

INSERT INTO node_access VALUES (0, 0, 'all', 1, 0, 0);

That fixed the lost content, but still, every time I tried to save a page, the table would be emptied.

It seems what happened was that the upgrade process didn't quite work. I looked at the schema for a 6.x install and it was different, the upgraded schema was broken in that default initializers were missing. This broke everything.

So, using PostgreSQL, how does one save the data and change the schema?

DBNAME is the current database
TARGET is the new database
DBUSER is the name of the drupal user
ADMIN is the database administrator
HOST is the database hostname

First step is to save the database
pg_dump --no-owner -U $DBUSER -h $HOST -D $DBNAME > $BACKUPNAME

The -D is important as it will create a backup of the database using full inserts.

Then backup the schema of an existing drupal install. (create a new install if need be)
pg_dump --no-owner -U $DBUSER -h $HOST -s drupal6db > drupal6schema.sql

You'll have to edit the "users" table definition and add "signature_format smallint DEFAULT 0 NOT NULL" because this field is not in version 6, but it will be in your original data and cause the re-import to fail.

Now, create a new database
createdb -U $ADMIN -h $HOST --encoding=UNICODE --owner=$DBUSER $TARGET

Create the schema in the new database
cat /root/drupal6schema.sql | psql -U $DBUSER -h $HOST $TARGET

Then apply the database data over it.

You will get some errors on schema definitions, but that is expected.

Now use the new database, and everything should be fixed. At least it was for me.