Results 1 to 5 of 5

Thread: Copy Postgres to another computer, database

  1. #1
    Join Date
    May 2009
    Posts
    23

    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

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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 .

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Copy Postgres to another computer, database

    Use 'pg_dump' to dump the database. The simplest invocation would be:
    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.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    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):

    $ 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 :

    $ psql -U postgres -c "drop database <dbname>;"
    Create the database as user postgres and target owner owname:

    $ psql -U postgres -c "create database <dbname> with owner <owname> encoding = 'UNICODE';"
    Now restore the dump:

    $ psql -U <owname> -d <dbname> -f <dbname>.sql

  5. #5
    Join Date
    Dec 2011
    Posts
    1

    Re: Copy Postgres to another computer, database

    Quote Originally Posted by MindSpace View Post
    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.

Similar Threads

  1. Unable to get a safe access while connecting to Postgres
    By Jagathi in forum Software Development
    Replies: 6
    Last Post: 27-07-2011, 08:20 PM
  2. Copy microsoft office from one computer to another
    By DutchDude in forum Windows Software
    Replies: 3
    Last Post: 04-08-2009, 12:50 PM
  3. Copy VHS tapes to computer
    By Laler in forum Windows Software
    Replies: 3
    Last Post: 31-07-2009, 09:00 AM
  4. Copy shows from Direct TV DVR to Computer
    By Bartholomew in forum Windows Software
    Replies: 3
    Last Post: 30-07-2009, 11:17 PM
  5. How to convert date format in postgres
    By Sayam in forum Software Development
    Replies: 3
    Last Post: 18-03-2009, 11:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,895,392.55816 seconds with 17 queries