Copy Postgres to another computer, database
I just installed Postgres and looking for some help to copy a Postgres database i am new to this so i need some information regarding Windows server also for testing server.please give me proper and exact commands and information that i need to use. also provide restoration process information .
thank you
Re: Copy Postgres to another computer, database
you can use dblink function to transfer data and table structure.psql and pg_dump are command line utilities. psql -n is used preferentially so you are not storing command line history,that you do not need if you are operating in batch mode .
Re: Copy Postgres to another computer, database
Use 'pg_dump' to dump the database. The simplest invocation would be:
Quote:
pg_dump -U <dbuser> --format p -f <outfile> <dbname>
Move the database file to the test system. To recreate the database on your test system, I would do the following:
dropdb -U <dbuser> <dbname>
createdb -U <dbuser> <dbname>
psql -U <dbuser> -d <dbname> -f <outfile>
there are options that can be used with 'pg_dump' to only get the data (or the schema) in the database dump. In that case, you'd only need to TRUNCATE the database tables.
Re: Copy Postgres to another computer, database
to copy a PostgreSQL database from one computer to another you canuse this :
create a dump using pg_dump and option -O (no owner):
Quote:
$ pg_dump -U postgres -O <dbname> > <dbname>.sql
On MacOSX,For PostgreSQL version 8.3.x the path to pg_dump has to be fully specified. it is /opt/local/lib/postgresql83/bin/pg_dump.
move dbname.sql to the destination system; all next steps perform there
you can remove the database dbname as database superuser postgres if required :
Quote:
$ psql -U postgres -c "drop database <dbname>;"
Create the database as user postgres and target owner owname:
Quote:
$ psql -U postgres -c "create database <dbname> with owner <owname> encoding = 'UNICODE';"
Now restore the dump:
Quote:
$ psql -U <owname> -d <dbname> -f <dbname>.sql
Re: Copy Postgres to another computer, database
Quote:
Originally Posted by
MindSpace
to copy a PostgreSQL database from one computer to another you canuse this :
create a dump using pg_dump and option -O (no owner):
On MacOSX,For PostgreSQL version 8.3.x the path to pg_dump has to be fully specified. it is /opt/local/lib/postgresql83/bin/pg_dump.
move dbname.sql to the destination system; all next steps perform there
you can remove the database dbname as database superuser postgres if required :
Create the database as user postgres and target owner owname:
Now restore the dump:
I didn't understand this for a while, even after I looked around for other solutions, as I'm new to postgresql and kept getting an error when trying to use user "postgres" but as my own user I got "Database [username] does not exist."
Apparently without specifying -d [db_name] it'll default to the username as the database name. As that wasn't given here, I had to look it up. After explicitly specifying a database (I had to use "-d template1" to connect to *a* database other than *the* database I was trying to drop), I was good.
Nota bene.