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

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

pg_dump -U postgres db_name > db_name.dump

and then

psql -U postgres db_name < db_name.dump

I created the database db_name the same way in both instances. In the new database when I run my Java program with a JPA query (or a JDBC query) I get this error:

"ERROR: relation "table1" does not exist"

The query is:

select count(0) from table1

I know I've got a connection because if I change the password in the connection parameters I get an error.

For some reason in the new PostgresQL instance it thinks that table1 does not exist in the imported schema.

If I change the query to

select count(0) from myschema.table1

Then it complains about permissions:

"ERROR: permission denied for schema myschema"

Why would the permissions be different?

The table table1 exists in myschema because I can see it in the pgAdmin tool. All the rows were imported into the new PostgresQL instance.

When I do a query from Java the combination of pg_dump and psql created a problem.

What do I need to do to solve this issue?

Thanks in advance.

19
задан Dean Schulze 19 August 2010 в 02:11
поделиться

2 ответа

Вы переходите на ту же версию PostgreSQL? Могут возникнуть проблемы, если вы сделаете дамп с помощью pg_dump 8.3 и попытаетесь восстановить его в Postgresql 8.4. В любом случае, предполагая, что это та же версия, попробуйте сделать следующее:

Сделайте дамп всех глобальных объектов, таких как пользователи и группы (не знаю, отсутствовали ли они в вашем дампе):

pg_dumpall -g -U postgres > globals.sql

Сделайте дамп схемы базы данных:

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

Сделайте дамп содержимого базы данных:

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

Теперь восстановите.

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

Это мои $0.02. Надеюсь, это поможет.

32
ответ дан 30 November 2019 в 03:28
поделиться

Мне удалось решить эту проблему, изменив привилегии базы данных на public CONNECT и привилегии схемы на public и postgres = USAGE и CREATE.

Мои сценарии резервного копирования, по-видимому, не сохранили привилегии, по крайней мере, при переходе с 8.3 на 8.4.

2
ответ дан 30 November 2019 в 03:28
поделиться
Другие вопросы по тегам:

Похожие вопросы: