Friday, December 07, 2007

Migrate PostgreSQL 8.1 Data to PostgreSQL 8.2

Install PSQL 8.2

Felix:~ sunfmin$ sudo port install postgresql82

Dump all the PSQL 8.1 Databases to a file

Using The new installed PSQL 8.2 's pg_dumpall to dump all the PSQL 8.1 databases

Felix:~ sunfmin$ /opt/local/lib/postgresql82/bin/pg_dumpall > ~/pg81_all_dump

Initialize PSQL 8.2 Database instance

Felix:~/Developments sunfmin$ sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'
Password:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /opt/local/var/db/postgresql82/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 32MB/204800
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql82/defaultdb/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

    /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
or
    /opt/local/lib/postgresql82/bin/pg_ctl -D /opt/local/var/db/postgresql82/defaultdb -l logfile start

Start your database

Felix:~/Developments sunfmin$ sudo su postgres -c "/opt/local/lib/postgresql82/bin/pg_ctl -D /opt/local/var/db/postgresql82/defaultdb -l /opt/local/var/log/postgresql82/postgres.log start"
server starting

You may encounter some problem like this following

Felix:~/Developments sunfmin$ sudo su postgres /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
Password:
/opt/local/lib/postgresql82/bin/postgres: /opt/local/lib/postgresql82/bin/postgres: cannot execute binary file

Felix:~/Developments sunfmin$ sudo  /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.


Felix:~/Developments sunfmin$ psql
psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

Restore all the data

Felix:~ sunfmin$ /opt/local/lib/postgresql82/bin/psql -f pg81_all_dump template1 -U postgres
You are now connected to database "postgres".
SET
SET
SET
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE DATABASE

No comments: