背景:
Ubuntu 14.04 で PostgreSQL 9.3.5 を使用しています。
悪いスクリプトの後、pg_dump で作成されたダンプ ファイルから復元する必要があるテーブルがあります。このテーブルには、このwiki ページに基づく監査トリガーがあります。ご覧のとおり、トリガー関数は hstore を使用しています。
エラー:
復元を試みると、次のようになります。
$ pg_restore -a --dbname=a193 -Fc --host=localhost --port=5434 --username=postgres -W --table=foo ~/tmp/a193.dump
Password:
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 4600; 0 26146 TABLE DATA foo u2su8s81ul0a52
pg_restore: [archiver (db)] COPY failed for table "foo": ERROR: type "hstore" does not exist
LINE 6: h_old hstore;
拡張子は確かに存在します。
=> \dx
List of installed extensions
+--------------------+---------+------------+--------------------------------------------------------------+
| Name | Version | Schema | Description |
+--------------------+---------+------------+--------------------------------------------------------------+
| dblink | 1.1 | public | connect to other PostgreSQL databases from within a database |
| hstore | 1.2 | public | data type for storing sets of (key, value) pairs |
| isn | 1.0 | public | data types for international product numbering standards |
| pg_stat_statements | 1.1 | public | track execution statistics of all SQL statements executed |
| pgcrypto | 1.0 | public | cryptographic functions |
| plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language |
| plpythonu | 1.0 | pg_catalog | PL/PythonU untrusted procedural language |
| postgres_fdw | 1.0 | public | foreign-data wrapper for remote PostgreSQL servers |
| uuid-ossp | 1.0 | public | generate universally unique identifiers (UUIDs) |
+--------------------+---------+------------+--------------------------------------------------------------+
(9 rows)
そして、クエリでそれを使用できます(postgresユーザーとして-上記で復元に使用しているのと同じ役割です):
=> select current_user;
+--------------+
| current_user |
+--------------+
| postgres |
+--------------+
(1 row)
=> \du
List of roles
+----------------+------------------------------------------------+-----------+
| Role name | Attributes | Member of |
+----------------+------------------------------------------------+-----------+
| postgres | Superuser, Create role, Create DB, Replication | {} |
| u2su8s81ul0a52 | | {} |
+----------------+------------------------------------------------+-----------+
=> select 'a=>1'::hstore;
+----------+
| hstore |
+----------+
| "a"=>"1" |
+----------+
(1 row)
質問:
- データベースにこの拡張機能がインストールされているのに、なぜこのエラーが発生するのですか?
- トリガーをドロップする以外に、この問題を回避するにはどうすればよいですか? トリガーをドロップすることは世界的に悪いことではありませんが、これは可能であるように思われ、本番データベースでは、誰かがデータの復元を行ったという監査証跡などを確認できるようにしたいと考えています.