简体   繁体   English

使用程序的图形界面在 PgAdmin 4 上备份和恢复 PostgreSQL 数据库

[英]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.我有一个使用 pgadmin 管理的 posgresql 数据库。 I would like to backup the database in a sql file on the server and on my pc.我想在服务器和我的电脑上的 sql 文件中备份数据库。 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.我可以备份和读取 sql 文件(它看起来是正确的)但我无法恢复。 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).我想避免在执行恢复之前必须删除数据库表,因为没有命令允许我删除一个 go 中的所有表(显然我总是指的是图形过程,我感兴趣的那个)。 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 Dockerfile 1

FROM dpage/pgadmin4:6.18

Dockerfile 2 Dockerfile 2

FROM kartoza/postgis:15-3.3

Docker Compose Docker 撰写

  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服务器.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我如何使用我在服务器上安装 pgAdmin 的程序并通过键入 pgadmin.domainname.it 访问该服务

  2. Steps to reproduce the problem (see attached photos)重现问题的步骤(见附图)

在此处输入图像描述

在此处输入图像描述

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)安装了 Docker 并运行 PgAdmin 容器的服务器的操作系统和浏览器:Ubuntu 22.04.1 LTS 64 位 - cpu arm Oracle 安培(更新)我的 PC 操作系统:8874414387 Pro968 系列 8874414387 8874414387使用的浏览器:Chrome(最新版)

  2. Error provided by PgAdmin (see photos) PgAdmin 提供的错误(见照片)

在此处输入图像描述

  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用户名:Federico 密码:abc1

Next I backup the database as shown above.接下来我备份数据库,如上所示。

Next I change the password using my application:接下来,我使用我的应用程序更改密码:

Username: Federico Password: abc2用户名:Federico 密码: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用户名:Federico 密码:abc1

Instead I have to use the following:相反,我必须使用以下内容:

Username: Federico Password: abc2用户名:Federico 密码: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.我尝试在 pgadmin.localhost 和 Linux Desktop 22.04.1 LTS 上做所有事情,但我遇到了同样的错误。

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

Thank you谢谢

It appears you are using a plain text format for your backup, so you should be using the query tool or psql to restore.看来您正在使用纯文本格式进行备份,因此您应该使用查询工具或 psql 来恢复。 Basically, this means you just need to run the sql script.基本上,这意味着您只需要运行 sql 脚本。 From the pg admin docs take note of the following (emphasis added):从 pg admin 文档中注意以下内容(强调):

On backing up:关于备份:

Select Plain to create a plain-text script file. Select Plain 创建纯文本脚本文件。 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.纯文本脚本文件包含 SQL 条语句和命令,您可以在 psql 命令行中执行这些语句和命令以重新创建数据库对象并加载表数据。 A plain-text backup file can be edited in a text editor, if desired, before using the psql program to restore database objects.如果需要,可以在文本编辑器中编辑纯文本备份文件,然后再使用 psql 程序恢复数据库对象。 Plain format is normally recommended for smaller databases;对于较小的数据库,通常建议使用纯格式; script dumps are not recommended for blobs.不建议将脚本转储用于 blob。 The SQL commands within the script will reconstruct the database to the last saved state of the database.脚本中的 SQL 命令会将数据库重建为数据库最后保存的 state。 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 .还原对话框提供了一种简单的方法来使用通过 pgAdmin 备份对话框获取的自定义、tar 或目录格式备份来重新创建数据库或数据库 object。您可以使用查询工具来回放在纯文本备份期间创建的脚本使用“备份”对话框制作

Further info see PGAdmin Backup/Restore and Postgres Backup更多信息请参阅PGAdmin 备份/恢复Postgres 备份

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM