error while trying to restore a postgres db - postgresql

I'm trying to restore a table in a db in postgres from a .sql file.
I used command pg_restore -d dbName file.sql. The user is a superuser. But I got several errors:
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 359; 1259 499945 TABLE fuller4t7 someName
pg_restore: [archiver (db)] could not execute query: ERROR: permission denied to create "pg_catalog.fuller4t7"
DETAIL: System catalog modifications are currently disallowed.
Command was: CREATE TABLE fuller4t7 (
gid integer NOT NULL,
geom public.geometry(MultiPolygon,4326)
);
Other errors are related with this one since the table was not created in the first place. I'm wondering what these errors mean. I'm using postgres 9.4 and I have PostGIS extensions added to the particular database.

Related

PostgreSQL 10 public schema default ownership conflicts with pg_restore --clean

On a PostgreSQL instance of v10.21, we created appuser for the operations regarding the application, and we don't usually have the credential of the superuser postgres.
It seems that postgres owns the public schema inside any database by default, even if the database is created and owned by appuser. This system behaviour conflicts with pg_restore --clean.
The --clean option means to clean before restoring, so when the process comes to dropping the public schema, it encounters errors saying could not execute query: ERROR: must be owner of schema public. See more details in the screenshot below.
I am wondering:
As a quick dirty workaround, should we just ignore the errors?
Or, should we get the superuser to change the owner to appuser? This action will suppress the errors but we don't know whether there is any complication after changing the system's default settings.
Screenshot of pg_restore --clean run-time errors:
...
... dropping other objects in the public schema ...
...
pg_restore: dropping SEQUENCE OWNED BY activity_id_seq
pg_restore: dropping SEQUENCE activity_id_seq
pg_restore: dropping TABLE activity
pg_restore: dropping COMMENT SCHEMA public
pg_restore: dropping SCHEMA public
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3; 2615 2200 SCHEMA public postgres
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of schema public
Command was: DROP SCHEMA public;
pg_restore: creating SCHEMA "public"
pg_restore: [archiver (db)] could not execute query: ERROR: schema "public" already exists
Command was: CREATE SCHEMA public;
pg_restore: creating COMMENT "SCHEMA public"
pg_restore: [archiver (db)] Error from TOC entry 4429; 0 0 COMMENT SCHEMA public postgres
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of schema public
Command was: COMMENT ON SCHEMA public IS 'standard public schema';
pg_restore: creating TABLE "public.activity"
pg_restore: creating SEQUENCE "public.activity_id_seq"
...
... creating other objects in the public schema ...
...
WARNING: errors ignored on restore: 3

How to migrate data from heroku to different vps?

I have a postgres db for my backend hosted in Heroku. I am changing vps now to a different vendor altogether.
I used following commands:
heroku pg:backups:capture
heroku pg:backups:download
to take dump file, and than ran the following comamnd to pg_restore to remote vps postgres (I have ssh to remote server):
pg_restore --verbose --clean --no-acl -h localhost -p 5444 -d databasename -U databaseuser latest.dump --no-owner -x
I get the following message/errors:
pg_restore: creating INDEX "public.partners_address_e9624195"
pg_restore: [archiver (db)] Error from TOC entry 5465; 1259 6124214 INDEX partners_address_e9624195 vumqvdyhbbakqw
pg_restore: [archiver (db)] could not execute query: ERROR: relation "public.partners_address" does not exist
Command was: CREATE INDEX "partners_address_e9624195" ON "public"."partners_address" USING "btree" ("businesses_id");
pg_restore: creating INDEX "public.partners_address_latitude_38918148755fccdf_uniq"
pg_restore: [archiver (db)] Error from TOC entry 5466; 1259 6124984 INDEX partners_address_latitude_38918148755fccdf_uniq vumqvdyhbbakqw
pg_restore: [archiver (db)] could not execute query: ERROR: relation "public.partners_address" does not exist
Command was: CREATE INDEX "partners_address_latitude_38918148755fccdf_uniq" ON "public"."partners_address" USING "btree" ("latitude");
pg_restore: creating INDEX "public.partners_address_location_id"
pg_restore: [archiver (db)] Error from TOC entry 5467; 1259 6124734 INDEX partners_address_location_id vumqvdyhbbakqw
pg_restore: [archiver (db)] could not execute query: ERROR: relation "public.partners_address" does not exist
Command was: CREATE INDEX "partners_address_location_id" ON "public"."partners_address" USING "gist" ("location");
pg_restore: creating INDEX "public.partners_address_longitude_6a1bd0c5aaf227a5_uniq"
pg_restore: [archiver (db)] Error from TOC entry 5468; 1259 6124985 INDEX partners_address_longitude_6a1bd0c5aaf227a5_uniq vumqvdyhbbakqw
pg_restore: [archiver (db)] could not execute query: ERROR: relation "public.partners_address" does not exist
Command was: CREATE INDEX "partners_address_longitude_6a1bd0c5aaf227a5_uniq" ON "public"."partners_address" USING "btree" ("longitude");
pg_restore: creating INDEX "public.partners_addressdummy_location_id"
pg_restore: [archiver (db)] Error from TOC entry 5484; 1259 6124296 INDEX partners_addressdummy_location_id vumqvdyhbbakqw
pg_restore: [archiver (db)] could not execute query: ERROR: relation "public.partners_addressdummy" does not exist
Command was: CREATE INDEX "partners_addressdummy_location_id" ON "public"."partners_addressdummy" USING "gist" ("location");
pg_restore: creating FK CONSTRAINT "public.partners_company partners_com_partner_id_68062c1b87fe6c02_fk_partners_partner_id"
pg_restore: creating FK CONSTRAINT "public.partners_companybankinginformation partners_comp_company_id_a85698afe499099_fk_partners_company_id"
pg_restore: creating FK CONSTRAINT "public.partners_fitnessinstantflooroffer partners_fi_business_id_db86587ff737cea_fk_partners_business_id"
pg_restore: creating FK CONSTRAINT "public.partners_partneraddons partners_par_addon_id_9f51a49f7df191c_fk_partners_addonmodel_id"
pg_restore: creating FK CONSTRAINT "public.partners_partneraddons partners_par_partner_id_409ed0f55743b48e_fk_partners_partner_id"
pg_restore: creating FK CONSTRAINT "public.partners_partner partners_partner_user_id_ca28b796442d283_fk_auth_user_id"
pg_restore: creating FK CONSTRAINT "public.partners_salonmenu partners_s_business_id_2e0ca679b0a24854_fk_partners_business_id"
pg_restore: creating FK CONSTRAINT "public.partners_sixdigitcode partners_s_business_id_345f911c3107973d_fk_partners_business_id"
pg_restore: creating FK CONSTRAINT "public.partners_trackbusinessdetails partners_t_business_id_1eb5c6794f6b1ada_fk_partners_business_id"
pg_restore: creating FK CONSTRAINT "public.recurrence_date recu_recurrence_id_4b67510aee5dda10_fk_recurrence_recurrence_id"
pg_restore: creating FK CONSTRAINT "public.recurrence_rule recu_recurrence_id_7ff1cb1803879eea_fk_recurrence_recurrence_id"
pg_restore: creating FK CONSTRAINT "public.recurrence_param recurrence_param_rule_id_5163400228e5d6ac_fk_recurrence_rule_id"
pg_restore: creating FK CONSTRAINT "public.social_auth_usersocialauth social_auth_usersocial_user_id_5af7eafade59e216_fk_auth_user_id"
WARNING: errors ignored on restore: 335
This operation was performed on an empty database. What am I doing wrong?
Help please!
Thanks

Restoring database giving error

When I try to restore my database backup, I am getting following error.
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 214; 1259 32064 TABLE country_amd0 userldd
pg_restore: [archiver (db)] could not execute query: ERROR: role "userldd" does not exist
Command was: ALTER TABLE country_amd0 OWNER TO userldd;
Does anybody know what this error is about?
Thank You.
A custom-format dump is just of the database its self, not the global state like users.
If you don't have a pg_dump --globals-only too, you will need to re-create any:
roles (users/groups)
tablespaces
and other global objects referenced by the dump.
It's a shame that pg_dump doesn't auto-include those if referenced by the dump, so you could optionally restore them too. A patch for this would be very welcome, but so far nobody's stepped up.

Error: Command was: SELECT pg_catalog.setval

I'm unable to restore my backup DB on heroku DB but I don't have any issue if I restore on my local env and I get no errors.
When I try to restore on heroku connect database I get this following error:
C:\Program Files\PostgreSQL\9.4\bin\pg_restore.exe --host
XXXXXX.compute-1.amazonaws.com --port 5432 --username
"XXXXokwpyzewicl" --dbname "d9uto7paqXXX" --no-password --verbose
"C:\Users\XXXX\Desktop\loans.backup"
pg_restore: connecting to
database for restore pg_restore: implied data-only restore
pg_restore: processing data for table "application_denial_reason_types"
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 5202; 0 16622 TABLE DATA application_denial_reason_types postgres
pg_restore: [archiver (db)] could not execute query: ERROR: relation "application_denial_reason_types" does not exist
Command was: COPY application_denial_reason_types (denial_reason_type_id, denial_reason_type_name, description, active, created_by, creat... pg_restore: executing SEQUENCE SET application_denial_reason_types_denial_reason_type_id_seq
pg_restore: [archiver (db)] Error from TOC entry 5672; 0 0 SEQUENCE SET
application_denial_reason_types_denial_reason_type_id_seq postgres
pg_restore: [archiver (db)] could not execute query: ERROR: relation
"application_denial_reason_types_denial_reason_type_id_seq" does not
exist LINE 1: SELECT pg_catalog.setval('application_denial_reason_types_de...
^
Command was: SELECT pg_catalog.setval('application_denial_reason_types_denial_reason_type_id_seq',
1, false);
How do I fix this error?
It tries to set value of not existing sequence:
pg_restore: [archiver (db)] could not execute query: ERROR: relation
"application_denial_reason_types_denial_reason_type_id_seq" does not
exist
to understand the reason take alook at the:
pg_restore: connecting to database for restore pg_restore: implied
data-only restore
If you check man pg_restore you'll find, that:
-a
--data-only
Restore only the data, not the schema (data definitions). Table data, large objects, and sequence values are restored, if
present in the archive.
So you probably have data structure on your local env, and this is why you set value for existing sequence. And there is not structure on heroku, so you get error.
Remove -a from pg_restore command to run DDL prior to data restore.

pg_restore tells schema "test" already exists but it isn't actually

When restoring a dump like this:
pg_restore --clean --create --exit-on-error --dbname=test test.tar
these error messages got printed out:
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 21; 2615 80924 SCHEMA test test
pg_restore: [archiver (db)] could not execute query: ERROR: schema "test" already exists
Command was: CREATE SCHEMA test;
but when:
select schema_name from information_schema.schemata;
these got printed out
schema_name
--------------------
pg_toast
pg_temp_1
pg_toast_temp_1
pg_catalog
public
information_schema
It seems like schema "test" doesn't exist yet,why do I got this kind of error?
What OS, which version of postgres dump was made, restored to same version?
Read this article, maybe it will help.
It states that there are some trivial issues with the --clean parameter,
and you probably should try to create database manually and restore to it without
the create and clean options.