Export DB with PostgreSQL's PgAdmin-III

前端 未结 2 1662
萌比男神i
萌比男神i 2020-12-09 22:18

How to export a Postgresql db into SQL that can be executed into other pgAdmin?

  • Exporting as backup file, doesn\'t work when there\'s a difference
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 22:42

    Export/Import with pg_dump and psql

    1.Set PGPASSWORD

    export PGPASSWORD='123123123';
    

    2.Export DB with pg_dump

    pg_dump -h <> -U <> <> > /opt/db.out 
    

    /opt/db.out is dump path. You can specify of your own.

    3.Then set again PGPASSWORD of you another host. If host is same or password is same then this is not required.

    4.Import db at your another host

    psql -h <> -U <> -d <> -f /opt/db.out
    

    If username is different then find and replace with your local username in db.out file. And make sure on username is replaced and not data.

    If you still want to use PGAdmin then see procedure below.

    Export DB with PGAdmin:

    Select DB and click Export.

    1. File Options
      • Name DB file name for you local directory
      • Select Format - Plain
    2. Ignore Dump Options #1
    3. Dump Options #2
      • Check Use Insert Commands
    4. Objects
      • Uncheck tables if you don't want any

    Import DB with PGAdmin:

    1. Create New DB.
    2. By keeping selected DB, Click Menu->Plugins->PSQL Console
    3. Type following command to import DB

      \i /path/to/db.sql
      

    If you want to export Schema and Data separately.

    Export Schema

    1. File Options
      • Name schema file at you local directory
      • Select Format - Plain
    2. Dump Options #1
      • Check Only Schema
      • Check Blobs (By default checked)

    Export Data

    1. File Options
      • Name data file at you local directory
      • Select Format - Plain
    2. Dump Options #1
      • Check Only Data
      • Check Blobs (By default checked)
    3. Dump Options #2
      • Check Use Insert Commands
      • Check Verbose messages (By default checked)

    Note: It takes time to Export/Import based on DB size and with PGAdmin it will add some more time.

提交回复
热议问题