Friday 17 August 2007

Migrating a postgreSQL database as a plain-text file

There was this postgreSQL database on a remote machine which I had to reconstruct on my local machine, the database structure and content was dumped as a .sql and I had to reconstruct from the .sql. I tried running the query file from pgAdmin's query tool but to no avail, it simply didn't work; no effect no error messages. I later found a solution which I describe below:

A database could be dumped in 2 ways; as an archive which can be restored from pgAdmin using the pg_restore tool or as a plain-text file like the .sql I had. To restore from plain-text files, one has to use psql command-line tool. For those of you using WinXP pro sp2 and installed your postgreSQL like me, here's how to do it:

Go to Start menu> All programs> PostgreSQl and select psql to 'postgres'

It starts up a command-line window already connected to a default database. If thats the database you want to run the queries on, fine. Else you would have to change the database by typing:

\c name_of_database

then you will have to change directory to the directory where your .sql resides using

\cd name_of_directory
all \ in the directory name should be typed as / cos psql is UNIX-based and would confuse windows' \ for commands. also try and ensure that file and directory names conform to 8.3 filename format. Mine did; I don't know if it will work if yours don't

finally execute the commands by typing

\i name_of_file

if you have any problems with the above procedure, let me know.

13 comments:

Randal L. Schwartz said...

What’s “postgre”? If you mean PostgreSQL, that’s pronounced “post gres cue ell”, which is usually shortened to “post gres” and hence “postgres”, not “postgre”.

bighead said...

Thanks. Corrections observed.

A Kel called Wonder ...... said...

Hum this is tech o! way to tech for me big head. Kudos. I'll pass and go to the other blog of yours.

A Kel called Wonder ...... said...
This comment has been removed by the author.
Afrobabe said...

Is this english? I think I am in the wrong page...

Femme said...

what the?

Manda said...

mmmh! too muc for my head abeg!

Chxta said...

If you are looking for a Linux distro that works completely out of the box and has the 'ease' of Window$ then try PC Linux OS.

Chxta said...

Meanwhile concerning Ubuntu, some young men have opened this site...

naijagal said...

nice one try oracle sometime:)

badderchic said...

thats why you are the one with the big head, us? no more space after music, movies and INTERESTING books. lol.

guess whos done updating?

bighead said...

@chxta: thanks but I'll be working with dreamlinux for now. When i'm tired of that, i'll move to opensuse pc linux OS will just have to join the queue and wait its turn

@badderchic: can't guess. tell me

Anonymous said...

Interesting to know.