Moving a database with pg_dump and psql -U postgres db_name < … results in “ERROR: relation ”table_name“ does not exist”

前端 未结 3 1633
终归单人心
终归单人心 2021-01-30 11:18

I moved my PostgresQL database from one hard drive to another using

pg_dump -U postgres db_name > db_name.dump

and then

psq         


        
相关标签:
3条回答
  • 2021-01-30 11:57

    Are you moving to the same version of PostgreSQL? There might be issues if you make a dump with pg_dump 8.3 and try to restore it in Postgresql 8.4. Anyway, assuming that it is the same version try the following:

    Dump all global objects, such as users and groups (don't know if they were missing in your dump):

    pg_dumpall -g -U postgres > globals.sql
    

    Dump schema of database:

    pg_dump -Fp -s -v -f db-schema.sql -U postgres dbname
    

    Dump contents of database:

    pg_dump -Fc -v -f full.dump -U postgres dbname
    

    Now restore.

    psql -f globals.sql
    psql -f db-schema.sql dbname
    pg_restore -a -d dbname -Fc full.dump
    

    That is my $0.02. Hope it helps.

    0 讨论(0)
  • 2021-01-30 11:57

    I was able to solve it by changing the database privileges to public CONNECT and the schema privileges for public and postgres = USAGE and CREATE.

    My backup scripts apparently didn't preserve the privileges, at least not when moving from 8.3 to 8.4.

    0 讨论(0)
  • 2021-01-30 12:23

    I encountered this problem. Then I realized that I forgot to install postgis extension.

    Don't forget to install the extensions you use.

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