无法将 hstore 扩展安装到新创建的架构中

dud*_*ein 5 postgresql pg-restore hstore

我有一个安装了 postgres 9.5 的 ubuntu 18.04 。

我的数据库“mydb”安装了 hstore。当我执行“\dx store”时,我确实有

List of installed extensions
  Name  | Version | Schema |                   Description                    
--------+---------+--------+--------------------------------------------------

hstore | 1.3     | public | data type for storing sets of (key, value) pairs
(1 row)
Run Code Online (Sandbox Code Playgroud)

当我使用某个备份文件执行 pg_restore 时,会创建一个也称为“mydb”的新模式,但它不包含“hstore”扩展名。“\dx”命令的结果是相同的。hstore 已经在我的 template1 中了。

pg_restore 失败并显示

pg_restore:[archiver(db)]无法执行查询:错误:类型“hstore”不存在

谁能指出问题出在哪里?

谢谢

vin*_*inh 3

备份是使用相同版本的 postgresql 创建的吗?转储/恢复周期通常假设数据库已提前创建,但转储应创建扩展。您可以搜索备份以查看它是否包含为您的架构创建扩展的指令:

     CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;
Run Code Online (Sandbox Code Playgroud)

如果您不使用公共架构,您可能还需要检查您的架构是否是在扩展之前创建的。

您可以在恢复之前尝试以下操作在 mydb 架构中创建 hstore 扩展:

     CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA mydb;
Run Code Online (Sandbox Code Playgroud)

或者,hstore 扩展可能未正确安装。

    # locate hstore|grep postgresql
    # dpkg -S /path/to/hstore.so
Run Code Online (Sandbox Code Playgroud)