简体   繁体   English

pg_restore:错误:尝试将 postgres 数据库导入到 heroku 时搜索存档时无法识别的数据块类型 (0)

[英]pg_restore: error: unrecognized data block type (0) while searching archive while trying to import postgres database to heroku

I was trying to import a local database to Heroku, I got inspired from this StackOverflow question Push database to Heroku: how to use Heroku pg:push .我试图将本地数据库导入到 Heroku,我从这个 StackOverflow 问题Push database to Heroku: how to use Heroku pg:push得到了启发。 The command I was running was我运行的命令是

PGUSER=postgres PGPASSWORD=mypassword heroku pg:push mydatabse_name DATABASE_URL -a myapp

I got this error pg_restore: error: unrecognized data block type (0) while searching archive :我收到这个错误pg_restore: error: unrecognized data block type (0) while searching archive

pg_dump: last built-in OID is 16383   
pg_dump: reading extensions
pg_dump: identifying extension members
pg_dump: reading schemas
...
pg_dump: dumping contents of table "public.user"
pg_restore: creating TABLE "public.alembic_version"
...
pg_restore: processing data for table "public.alembic_version"
pg_restore: error: unrecognized data block type (0) while searching archive
 !    pg_restore errored with 1

I wonder how could I fix this issue?我想知道如何解决这个问题?

I have encountered this issue by running this command我通过运行此命令遇到了这个问题

pg_dump -f database_output_name --no-owner --no-acl -U user_name name_of_your_local_database
  • database_output_name name of the output file you can rename it whatever backup, database...etc database_output_name output 文件的名称,您可以将其重命名为任何备份、数据库...等
  • user_name : the postgres sql user_name mainly postgres user_name : postgres sql user_name 主要是postgres
  • name_of_your_local_database : is the name of your database: mydb or whatever the name you gave if you forgot it you can check in PgAdmin name_of_your_local_database :是您的数据库的名称:mydb 或您提供的任何名称,如果您忘记了它,您可以在 PgAdmin 中查看
  • pg_dump I have export it to global path that is why I am using it like this, other ways you can call it with the absolute path ie: C:\"Program Files"\PostgreSQL\14\bin\pg_dump pg_dump我已经将它导出到全局路径,这就是为什么我这样使用它,其他方式你可以用绝对路径调用它,即: C:\"Program Files"\PostgreSQL\14\bin\pg_dump

the grenerated ourput file shoule look something like this生成的 ourput 文件看起来像这样

--
-- PostgreSQL database dump
--

-- Dumped from database version 14.1
-- Dumped by pg_dump version 14.1

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: alembic_version; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.alembic_version (
    version_num character varying(32) NOT NULL
);

...

Now run this command to create the database on heroku现在运行此命令在 heroku 上创建数据库

heroku pg:psql --app heroku_app_name < database_output_name

If you want to reset your database you can run this command如果你想重置你的数据库,你可以运行这个命令

heroku pg:reset -a heroku_app_name

Now you can check the database on heroku by clicking on postgres link现在您可以通过单击 postgres 链接查看 heroku 上的数据库

heroku_preview

you should see something like this, if the number of rows is 0 you probably have empty database.你应该看到类似这样的东西,如果行数是 0 你可能有空数据库。

数据库 heroku 信息

Co.net to heroku database via PgAdmin Co.net 通过 PgAdmin 到 heroku 数据库

  • Open your PgAdmin right click on Servers and create new server let us name it Heroku打开你的 PgAdmin 右键单击服务器并创建新服务器让我们将其命名为 Heroku

  • Now click on Connection tab and fill up those information, you can find them in the hroku app under settings scrool to Config Vars reveal vars=> DATABASE_URL现在单击“连接”选项卡并填写这些信息,您可以在 hroku 应用程序的设置 scrool 下找到它们,以Config Vars reveal vars=> DATABASE_URL

the format of database url is like so: postgres://user:password@host:port/database ex: postgres://unancmnpxrgkmp:ababd6bcfed84a29549c32278204762d41b04be284a8b81750cbb6d356f8bcc7@ec2-54-209-221-231.compute-1.amazonaws.com:5432/d22q7soeu9pv6u So fill up the information like so the format of database url is like so: postgres://user:password@host:port/database ex: postgres://unancmnpxrgkmp:ababd6bcfed84a29549c32278204762d41b04be284a8b81750cbb6d356f8bcc7@ec2-54-209-221-231.compute-1.amazonaws.com:5432/d22q7soeu9pv6u所以像这样填写信息

  • Host name/address: host ie: ec2-54-209-221-231.compute-1.amazonaws.com主机名/地址:主机即: ec2-54-209-221-231.compute-1.amazonaws.com
  • Maintainace database: database ie: d22q7soeu9pv6u Maintainace数据库:数据库即: d22q7soeu9pv6u
  • username: username ie: unancmnpxrgkmp用户名:用户名即: unancmnpxrgkmp
  • password => password ie: ababd6bcfed84a29549c32278204762d41b04be284a8b81750cbb6d356f8bcc7密码 => 密码即: ababd6bcfed84a29549c32278204762d41b04be284a8b81750cbb6d356f8bcc7

PgAdmin 新服务器

Click on save now you should see something like this once you open your server.现在点击保存,一旦你打开你的服务器,你应该会看到类似这样的东西。 You should scroll down until you find the name of your database d22q7soeu9pv6u above, you can open it and check the tables, if you do not find it refrech, make sure you create everything correctly您应该向下滚动,直到在上面找到您的数据库名称d22q7soeu9pv6u ,您可以打开它并检查表格,如果没有找到它,请刷新,确保您正确创建了所有内容

Pg 管理员 Heroku 服务器

Heroku 你的数据库

Yeeeees, finally ElhamdulilAllah:D Yeeeees,最后 ElhamdulilAllah:D

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

相关问题 Python function 到 pg_restore 谷歌云 SQL 数据库 - Python function to pg_restore a Google Cloud SQL database 不同服务器之间的 pg_dump 和 pg_restore 具有对要转储的数据的选择标准 - pg_dump and pg_restore between different servers with a selection criteria on the data to be dumped 如何更改列的顺序,使其不会破坏 pg_restore 的导入 - How to I change the order of my columns so it doesn't break an import with pg_restore 从 python 调用 pg_restore - Call pg_restore from python 在转储文件上使用pg_restore - Using pg_restore on dump file 有没有一种方法可以使用pg_restore自动解压缩? - Is there a way to unzip automatically with pg_restore? 尝试导入套接字时出错? - Error while trying to import socket? 尝试在 MySQL 数据库中设置枚举数据类型时出现问题 - Issue while trying to set enum data type in MySQL database Django:尝试在 postgres 数据库中添加数据时出错 - Django:Error trying to add data in postgres database generate_tfrecord.py:错误:无法识别的 arguments - 尝试为测试和训练数据创建 TF 记录文件时出错 - generate_tfrecord.py: error: unrecognized arguments - error while trying to create TF Record files for test and train data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM