我正在try 从转储文件恢复表."VCCFinder-在开源项目中查找潜在漏洞以协助代码审计"一文中的脚注说明了这一点,团队使用pg_dump创建的转储文件可以使用pg_restore读取.如图paper footnote 所示,用红线强调.这就是我开始的地方.

1.使用pg_Restore命令

通过键入您的论文中提到的命令:VCCFinder:查找开源项目中的潜在漏洞以帮助代码审计:

pg_restore -f vcc_base I:\OneDrive\PractiseProject\x_prjs\m_firmware_scan\m_firmware_scan.ref\vcc-database\vccfinder-database.dump

Windows CMD返回了一条错误消息:

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

因为我try 了不同版本的操作,包括v14.4、v9.6、v9.4和v9.3,结果是相同的错误消息.

2.使用psql命令

然后我转向另一个方向:使用psql.在键入命令后,

psql -v ON_ERROR_STOP=1 -U postgres < I:\OneDrive\PractiseProject\x_prjs\m_firmware_scan\m_firmware_scan.ref\vcc-database\vccfinder-database.dump

除PostgreSQL 14.4环境外,返回的错误信息为:

psql: SCRAM authentication requires libpq version 10 or above

在PostgreSQL 14.4环境下,返回的消息为:

SET
SET
SET
SET
SET
SET
ERROR:  schema "export" already exists

如果我删除-v ON_ERROR_STOP=1选项,返回的消息将如下所示:

SET
SET
SET
SET
SET
SET
ERROR:  schema "export" already exists
SET
SET
SET
ERROR:  type "public.hstore" does not exist
LINE 27:     patch_keywords public.hstore
                            ^
ERROR:  relation "cves" already exists
ERROR:  relation "repositories" already exists
ERROR:  relation "commits" does not exist
invalid command \n
invalid command \N
invalid command \N
...

(Solved)我试图解决上面错误消息中显示的不可读代码问题,在Windows CMD中输入chcp 65001, chcp 437等将字符集更改为UTF8 or American English,但没有帮助.但在Visual Studio中查看转储文件的源代码后,不难推断这些错误消息是由转储文件中的psql命令引起的.

在错误消息变得可以理解之后,我将重点放在一个特定的错误消息上:

ERROR:  type "public.hstore" does not exist
LINE 27:     patch_keywords public.hstore

因此,我在"公共模式"下面手动创建了一个"hstore"类型,在错误消息变为以下内容之后:

SET
SET
SET
SET
SET
SET
SET
ERROR:  schema "export" already exists
SET
SET
SET
ERROR:  relation "commits" already exists
ERROR:  relation "cves" already exists
ERROR:  relation "repositories" already exists
ERROR:  malformed record literal: ""do"=>"1", "if"=>"0", "asm"=>"41", "for"=>"5", "int"=>"13", "new"=>"0", "try"=>"0", "auto"=>"0", "bool"=>"0", "case"=>"0", "char"=>"1", "else"=>"0", "enum"=>"0", "free"=>"0", "goto"=>"0", "long"=>"15", "this"=>"0", "true"=>"0", "void"=>"49", "alloc"=>"0", "break"=>"0", "catch"=>"0", "class"=>"0", "const"=>"0", "false"=>"0", "float"=>"0", "short"=>"0", "throw"=>"0", "union"=>"0", "using"=>"0", "while"=>"1", "alloca"=>"0", "calloc"=>"0", "delete"=>"0", "double"=>"0", "extern"=>"4", "friend"=>"0", "inline"=>"18", "malloc"=>"0", "public"=>"0", "return"=>"4", "signed"=>"1", "sizeof"=>"0", "static"=>"32", "struct"=>"4", "switch"=>"0", "typeid"=>"0", "default"=>"0", "mutable"=>"0", "private"=>"0", "realloc"=>"0", "typedef"=>"0", "virtual"=>"0", "wchar_t"=>"0", "continue"=>"0", "explicit"=>"0", "operator"=>"0", "register"=>"0", "template"=>"0", "typename"=>"0", "unsigned"=>"23", "volatile"=>"23", "namespace"=>"0", "protected"=>"0", "const_cast"=>"0", "static_cast"=>"0", "dynamic_cast"=>"0", "reinterpret_cast"=>"0""
DETAIL:  Missing left parenthesis.
CONTEXT:  COPY commits, line 1, column patch_keywords: ""do"=>"1", "if"=>"0", "asm"=>"41", "for"=>"5", "int"=>"13", "new"=>"0", "try"=>"0", "auto"=>"0", "bo..."
ERROR:  syntax error at or near "l022_save"
LINE 1: l022_save, pl022_load, s);
        ^
invalid command \n
invalid command \N
invalid command \N
...

现在已经创建了三个表,但是其中没有任何内容.

3.安装hstore

在搜索"hstore"hstore type does not exist with hstore installed postgresql之后,我意识到应该安装"hstore",而不是手动创建.因此,我在psql命令行中键入了以下内容: postgres=# create EXTENSION hstore;,并且有新的错误消息:

SET
SET
SET
SET
SET
SET
SET
ERROR:  schema "export" already exists
SET
SET
SET
CREATE TABLE
ERROR:  relation "cves" already exists
ERROR:  relation "repositories" already exists
ERROR:  missing data for column "hunk_count"
CONTEXT:  COPY commits, line 23201: "11388700   178     \N      other_commit    1d6198c3b01619151f3227c6461b3d53eeb711e5\N      blueswir1@c046a42c-6fe2-441..."
ERROR:  syntax error at or near "l022_save"
LINE 1: l022_save, pl022_load, s);
        ^
invalid command \n
invalid command \N
invalid command \N
...

尽管如此,这三个表格中没有任何内容.

4.生成并查看表格

在查看转储文件的源代码并try 修复"hank_count"问题后,以失败告终.我突然想到上面的错误消息只是由一行特殊的代码引起的.因此,我已经删除了该行,旧的错误消息也消失了,但有新的错误消息是由另一行引起的.最后,我总共删除了10行,与总行数351409相比,这些被删除的部分可以忽略不计.并且有三个表不再是空的,如pgAdmin4所示.

然而,pgADmin只演示了这些表的 struct ,我仍然不知道如何查看其中的内容.通过参考2 Ways to View the Structure of a Table in PostgreSQL,我输入了

SELECT 
   *
FROM 
   export.repositories/ export.cves/ export.commits
WHERE 
   TRUE

to generate and view corresponding tables in pgAdmin 4. For example, final cve table:final cve table

5.最后

回顾这些步骤,这些都是容易的步骤,但对于一个不熟悉工具或操作的人来说,为了一个简单的目的,一步一步地搜索和打字可能需要几天的时间.我希望这篇文章能对我这样的人有用.


然而,我不太熟悉psql命令或任何关于PostgreSQL的东西,事实上,我以前从未使用过它们.因此,我想知道是否有人能指出我在这些try 中可能犯下的一些错误,或者为我的困境提供一些建议.

推荐答案

解决了,就像我在上面展示的那样.

Postgresql相关问答推荐

我无法在过程中提交

从数据集中提取彼此喜欢的用户(&Q;)

将XML解析从T-SQL迁移到Postgres时出现问题

在Axum 0.5中,如何在一个请求处理程序中同时使用数据库和路径解析?

错误:用户需要系统密码:postgres

对 VOLATILE 函数的调用会 destruct SELECT 语句的原子性

PostgreSQL 中的 Datum 数据类型是什么以及它的用途是什么?

如何在 postgres 中查询键设置为空值的 jsonb 字段

找出两个表之间的差异

Postgres 根据自己的估计 Select 一个更费时的查询计划

转换数组类型

sql:转换参数 $1 类型:不支持的类型 []int,in 的一部分

PostgreSQL 输入结束时的语法错误

try 访问本地主机中的数据库时如何解决Error: The server does not support SSL connections?

Postgres NOT IN (null) 没有结果

如何使用 WITH RECURSIVE 子句进行 Select

判断materialized视图的上次刷新时间

避免通过 JPA 将null值插入数据库表

使用 Spring、Hibernate 和 C3P0 管理多租户 Web 应用程序中的连接池

SQL 函数返回类型:TABLE vs SETOF 记录