[英]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 主要是postgresname_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 上的数据库
you should see something like this, if the number of rows is 0 you probably have empty database.你应该看到类似这样的东西,如果行数是 0 你可能有空数据库。
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
所以像这样填写信息
ec2-54-209-221-231.compute-1.amazonaws.com
ec2-54-209-221-231.compute-1.amazonaws.com
d22q7soeu9pv6u
d22q7soeu9pv6u
unancmnpxrgkmp
unancmnpxrgkmp
ababd6bcfed84a29549c32278204762d41b04be284a8b81750cbb6d356f8bcc7
ababd6bcfed84a29549c32278204762d41b04be284a8b81750cbb6d356f8bcc7
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
,您可以打开它并检查表格,如果没有找到它,请刷新,确保您正确创建了所有内容
Yeeeees, finally ElhamdulilAllah:D Yeeeees,最后 ElhamdulilAllah:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.