Import SQL dump into PostgreSQL database

前端 未结 15 1605
我寻月下人不归
我寻月下人不归 2020-12-04 04:23

We are switching hosts and the old one provided a SQL dump of the PostgreSQL database of our site.

Now, I\'m trying to set this up on a local WAMP server to test thi

相关标签:
15条回答
  • 2020-12-04 04:51

    Postgresql12

    from sql file: pg_restore -d database < file.sql

    from custom format file: pg_restore -Fc database < file.dump

    0 讨论(0)
  • 2020-12-04 04:52

    You can do it in pgadmin3. Drop the schema(s) that your dump contains. Then right-click on the database and choose Restore. Then you can browse for the dump file.

    0 讨论(0)
  • 2020-12-04 04:52

    I noticed that many examples are overcomplicated for localhost where just postgres user without password exist in many cases:

    psql -d db_name -f dump.sql
    
    0 讨论(0)
  • 2020-12-04 04:54

    Follow the steps:

    1. Go psql shell
    2. \c db_name
    3. \i path_of_dump [eg:-C:/db_name.pgsql]
    0 讨论(0)
  • 2020-12-04 04:55

    That worked for me:

    sudo -u postgres psql db_name < 'file_path'
    
    0 讨论(0)
  • 2020-12-04 05:00
    psql databasename < data_base_dump
    

    That's the command you are looking for.

    Beware: databasename must be created before importing. Have a look at the PostgreSQL Docs Chapter 23. Backup and Restore.

    0 讨论(0)
提交回复
热议问题