Migrating from a version 7.4 to a version 8.2 postgreSQL database, on Debian Etch

  1. Compiling and setting up postgres, followin the INSTALL file
    ./configure
    I just ran configure with no customization.

    Had to install readline support:
    apt-get install libreadline5-dev

    make (Debian has renamed Gnu make to just make)

    su (if you use su -, you'll need to cd back to the directory where you unpacked the pg source)

    If you don't have a user postgres, add it
    adduser postgres
    I didn't need to add the postgres user since that user allready exists from my previous 7.4 installation

    make install

    Create the folder for the database:
    mkdir /usr/local/pgsql/data && chown postgres /usr/local/pgsql/data

    su - postgres

    /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
    After initdb it's probably a good idea to take a backup of the data directory, so that you can just copy in a fresh copy of the db cluster without running initdb if the import fails.

    Make sure your new database works
    /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data > /usr/local/pgsql/data/logfile 2>&1 &
    /usr/local/pgsql/bin/createdb test
    /usr/local/pgsql/bin/psql test
    Then, stop the postgres instance you started:
    /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data/


  2. Dump the old database cluster:
    /usr/local/pgsql/bin/pg_dumpall -h /var/run/postgresql/ > /tmp/pg74.sql
    It's important to use the version of pg_dumpall from the 8.2 installation.

  3. Stop the old 7.4 postgres database, In my case:
    exit
    /etc/init.d/postgresql-7.4 stop
    su - postgres

  4. Start postgresql 8.2 again:
    /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data > /usr/local/pgsql/data/logfile 2>&1 &

  5. Now, time to try to import the 7.4 database:
    /usr/local/pgsql/bin/psql -v ON_ERROR_STOP=1 -f /tmp/pg74.sql

    the -v ON_ERROR_STOP makes the import abort if any error is encountered, and using the -f flag to specify the file, instead of using <, makes psql output line numbers from the dump, when outputting error messages.

    This step probably won't work without errors/notices.

  6. At this point, this sequence of commands can come in handy:

    /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data/
    exit
    rm -rf /usr/local/pgsql/data/
    cp -r /usr/local/pgsql/data-backup/ /usr/local/pgsql/data
    chown -R postgres.postgres /usr/local/pgsql/data
    su - postgres
    /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data > /usr/local/pgsql/data/logfile 2>&1 &
    
  7. First obstacle are these lines in the dump file:
    CREATE ROLE postgres;
    ALTER ROLE postgres WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN;
    I simply removed them from the dump file.

    I also removed any modifications done to the template-databases.

    I got an error from some of the functions which I had added from old contrib. Since I don't actually use the functions this provides, I simply deleted this from the dump file.
    psql:/tmp/pg74.sql:65031: ERROR: could not access file "$libdir/fuzzystrmatch": No such file or directory


  8. Well... thats it
    2 hours after starting, I'm done