postgresqldatabase-backupspgadmin-4database-restore

Backup and restore a PostgreSQL database on PgAdmin 4 using the program's graphical interface


I have a posgresql database which I manage with pgadmin. I would like to backup the database in a sql file on the server and on my pc. Furthermore, I would like to restore the same database by deleting the data previously present. I would like to perform the whole procedure using the graphical procedure (no code). I can't find the right options to use to create backup and restore. I can backup and read the sql file (it looks correct) but I can't restore. I would like to avoid having to delete the database tables before performing the restore because there is no command that allows me to delete all the tables in one go (obviously I am always referring to the graphical procedure, the one that interests me). I've seen videos that show how to do it but they all perform a restore on a different database, I'm interested in always operating on the same database. In some of my attempts I get this error:

pg_restore: error: input file appears to be a text format dump. Please use psql.

I have these versions of the 2 programs (as you can see I have the latest versions):

FROM kartoza/postgis:15-3.3
FROM dpage/pgadmin4:6.18
  1. Program version and how I got the software

Dockerfile 1

FROM dpage/pgadmin4:6.18

Dockerfile 2

FROM kartoza/postgis:15-3.3

Docker Compose

  postgresql-postgis:
    build: ./postgresql-postgis
    image: image-postgresql-postgis-eb:v.1.0
    container_name: container-postgresql-postgis-eb
    restart: always
    networks:
      - eb
    volumes:
      - data-postgresql:/var/lib/postgresql
    environment:
      POSTGRES_USER: "..."
      POSTGRES_PASSWORD: "..."
      POSTGRES_DB: "..."
      ALLOW_IP_RANGE: "0.0.0.0/0"
    depends_on:
      - traefik

  pgadmin:
    build: ./pgadmin
    image: image-pgadmin-eb:v.1.0
    container_name: container-pgadmin-eb
    restart: always
    networks:
      - eb
    labels:
      traefik.http.services.pgadmin.loadbalancer.server.port: 80
      traefik.http.services.pgadmin.loadbalancer.server.scheme: http
      traefik.http.routers.pgadmin.rule: Host(`www.pgadmin.${NOME_A_DOMINIO}`)
      traefik.http.routers.pgadmin.tls.domains[0].main: pgadmin.${NOME_A_DOMINIO}
      traefik.http.routers.pgadmin.tls.domains[0].sans: www.pgadmin.${NOME_A_DOMINIO}
      traefik.http.routers.pgadmin.tls.certresolver: leresolver
    volumes:
      - type: bind
        source: ./volumes/data-pgadmin/servers.json
        target: /pgadmin4/servers.json
    environment:
      PGADMIN_DEFAULT_EMAIL: ...@gmail.com
      PGADMIN_DEFAULT_PASSWORD: ...
    depends_on:
      - traefik
      - postgresql-postgis

servers.json

{
  "Servers": {
    "1": {
      "Group": "Server PostgreSQL e PostGIS",
      "Name": "Server 1",
      "Port": 5432,
      "Username": "...",
      "Host": "postgresql-postgis",
      "SSLMode": "prefer",
      "MaintenanceDB": "postgres"
    }
  }
}
  1. How am I using the program I have installed pgAdmin on a server and I access the service by typing pgadmin.domainname.it

  2. Steps to reproduce the problem (see attached photos)

enter image description here

enter image description here

Note: I actually ran a lot of tests trying to change the backup and restore methods. It is physically impossible to list them all in this discussion. I do not exclude that among all these attempts there is one that works.

  1. OS and browser used OS of the server where Docker is installed and where the PgAdmin container runs: Ubuntu 22.04.1 LTS 64bit - cpu arm Ampere of Oracle (updated) OS of my PC: Windows 10 Pro 64bit cpu intel eighth series (updated) Browser used: Chrome (latest version)

  2. Error provided by PgAdmin (see photos)

enter image description here

  1. What I have under the hood and what I want to do

I have an application that allows users to register.

I register with the following credentials:

Username: Federico Password: abc1

Next I backup the database as shown above.

Next I change the password using my application:

Username: Federico Password: abc2

Finally I restore all the database tables as shown above.

Using the browser I should login to the application using the following credentials:

Username: Federico Password: abc1

Instead I have to use the following:

Username: Federico Password: abc2

I also get the error shown above warning me that the restore didn't happen.

If you need any other information let me know.

I tried doing everything on pgadmin.localhost and Linux Desktop 22.04.1 LTS but I get the same errors.

pg_restore: error: input file appears to be a text format dump. Please use psql.

Thank you


Solution

  • It appears you are using a plain text format for your backup, so you should be using the query tool or psql to restore. Basically, this means you just need to run the sql script. From the pg admin docs take note of the following (emphasis added):

    On backing up:

    Select Plain to create a plain-text script file. A plain-text script file contains SQL statements and commands that you can execute at the psql command line to recreate the database objects and load the table data. A plain-text backup file can be edited in a text editor, if desired, before using the psql program to restore database objects. Plain format is normally recommended for smaller databases; script dumps are not recommended for blobs. The SQL commands within the script will reconstruct the database to the last saved state of the database. A plain-text script can be used to reconstruct the database on another machine, or (with modifications) on other architectures.

    On restoring:

    The Restore dialog provides an easy way to use a Custom, tar, or Directory format backup taken with the pgAdmin Backup dialog to recreate a database or database object. You can use the Query Tool to play back the script created during a plain-text backup made with the Backup dialog.

    Further info see PGAdmin Backup/Restore and Postgres Backup