Postgres转储不包括损坏的页面块

时间:2019-04-05 10:16:25

标签: postgresql psql dump corruption

我试图提取我的数据库。在转储时,我收到以下错误。我知道数据库中的表已损坏,我可以使用exclude选项排除损坏的表并转储其余表。但是我正在寻找一个选项来转储即使是无效表块之外的损坏表。

我以前执行转储的命令是:

pg_dump -U postgres -p 5432 -d DBNAME -v -n SCHEMA_NAME -f "OUTFILE.sql"

错误打印:

 pg_dump: Dumping the contents of table "TABLE_NAME" failed: PQgetResult() failed.
    pg_dump: Error message from server: ERROR:  invalid page in block 2145280 of relation base/16384/25464

我能够访问损坏的表及其数据。因此,我相信可以访问的部分数据可以转储。如果有可能,请分享。

1 个答案:

答案 0 :(得分:2)

您可以设置defmodule TexasTechWeb.TokenController do use TexasTechWeb, :controller alias TexasTech.{Repo, User, Token, UserService} import Ecto.Query IO.inspect "##############Token Controller#############" def confirm_email(conn, %{"code" => code}) do case Repo.one(fetch_valid_token_q(code, "email_confirmation")) do %Token{user: user} = token -> case UserService.confirm_and_update_token(user, token, :email_verified_at) do {:ok, %{user: _u, token: _t}} -> render(conn, "email_confirmed.html") {:error, _, _, _} -> text(conn, "there was a problem") end nil -> conn |> put_status(404) |> render(TexasTechWeb.ErrorView, :"404") end end def reset_password(conn, %{"code" => code}) do IO.inspect "##########inside rest_password###########" case Repo.one(fetch_valid_token_q(code, "password_reset")) do %Token{} = token -> changeset = User.changeset(%User{}, %{}) render(conn, "reset_password.html", code: code, changeset: changeset) nil -> conn |> put_status(404) |> render(TexasTechWeb.ErrorView, :"404") end end def to_hash(ast) do :sha256 |> :crypto.hash(ast) |> Base.encode16 end def change_password(conn, %{"user" => %{"code" => code, "password" => password, "repeated_password" => repeated_password}}) do token = Repo.one(fetch_valid_token_q(code, "password_reset")) changeset = User.change_password_changeset(token.user, %{password: String.downcase(to_hash(password)), repeated_password: String.downcase(to_hash(repeated_password))}) if changeset.valid? do Repo.update(changeset) render(conn, "password_changed.html") else changeset = User.changeset(%User{}, %{}) conn |> put_flash(:info, "Wrong, try again!") |> render("reset_password.html", code: code, changeset: changeset) end end def fetch_valid_token_q(code, type) do from t in Token, where: t.code == ^code, where: t.type == ^type, where: t.used == false, where: t.expires_at >= ^Timex.now(), join: assoc(t, :user), preload: :user end end ,然后PostgreSQL应该将此类页面归零(并忽略)。