Postgresql – pgAdmin IV and PostgreSQL 12.0: ERROR: schema “public” already exists

pgadminpgadmin-4postgresqlpostgresql-12

I have a database backup from pgAdmin III with PostgreSQL 12.0 (Ubuntu 12.0-2.pgdg16.04+1) on Ubuntu 16.04 LTS.

I would like to restore this database on my pgAdmin IV with PostgreSQL 12.0 on Docker containers (i.e. pgAdmin IV and PostgreSQL (PostGIS)). The images are: kartoza/postgis:12.0 and dpage/pgadmin4:4.14.

The problem is when I restore the database, pgAdmin IV output shows the following error message:

pg_restore: connecting to database for restore
pg_restore: creating SCHEMA "public"
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 7; 2615 2200 SCHEMA public postgres
pg_restore: error: could not execute query: ERROR:  schema "public" already exists
Command was: CREATE SCHEMA public;
pg_restore: creating COMMENT "SCHEMA public"
[...]
pg_restore: connecting to database for restore
pg_restore: creating SCHEMA "public"
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 7; 2615 2200 SCHEMA public postgres
pg_restore: error: could not execute query: ERROR:  schema "public" already exists
Command was: CREATE SCHEMA public;
pg_restore: creating COMMENT "SCHEMA public"
[...]
pg_restore: creating FK CONSTRAINT "public.places_pilot_area places_pilot_area_fk_street_id"
pg_restore: warning: errors ignored on restore: 1
pg_restore: creating FK CONSTRAINT "public.layer_reference fk_reference_layer_reference1"
[...]
pg_restore: creating FK CONSTRAINT "public.places_pilot_area places_pilot_area_fk_street_id"
pg_restore: warning: errors ignored on restore: 1

I would not like to show these error messages, because they seem to be warnings and not errors (PostgreSQL is trying to create a public schema where it already exists). These errors are not shown on pgAdmin III when I restore using the same database.

There is this similar question. According to that answer, the error is harmless, but I would like to remove it from pgAdmin IV output.

I've already tried to restore with: (1) default options; (2) create option turned on; (3) clean option turned on; and (4) create and clean options turned on; however no success, all previous options result on an error message.

I'm afraid of ignoring these warnings and in the future true errors appear and I do not see them.

Thank you in advance.

Best Answer

Well, I was able to solve my problem by another path.

I suspected the problem was related to pgAdmin III and not PostgreSQL, then I opened my remote server through pgAdmin IV and I backed my remote database up.

After that, on pgAdmin IV, I restored the database and it worked fine, with no error.

Then, I believe the problem is related to creating a backup on pgAdmin III and restore it on pgAdmin IV.

If someone gets the same error in the future, please, use just pgAdmin IV to avoid problems.