我正在尝试根据 2009 年的 SO 回答在 postgresql 中创建数据库副本,但遇到了问题。
在 Postgres 9.3.9 中,这会创建一个没有关系的数据库(gcis 数据库存在并且有表和数据):
postgres=# CREATE DATABASE gcis_rollback WITH TEMPLATE gcis OWNER postgres;
CREATE DATABASE
postgres=# \c gcis_rollback
You are now connected to database "gcis_rollback" as user "postgres".
gcis_rollback=# \d
No relations found.
我使用命令行得到相同的结果createdb
:
~$ createdb -O postgres -T gcis gcis_rollback2
~$ psql gcis_rollback2
psql (9.3.9)
Type "help" for help.
gcis_rollback2=# \d
No relations found.
为什么我看不到此数据库的完整副本?
背景- 这是一个开发服务器,我可以在其中断开连接以制作副本。我想要的只是一个本地副本,以便在使用 Perl 框架Module::Build::Database构建补丁来开发/测试数据库模式更改时便于回滚。
附加信息:
gcis=# \l+ gcis
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
------+----------+----------+-------------+-------------+-------------------+-------+------------+-------------
gcis | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 35 MB | pg_default |
gcis=# \d
List of relations
Schema | Name | Type | Owner
---------------+------------------------------+----------+--------
gcis_metadata | _report_editor | table | ubuntu
...
(57 rows)
感谢@a_horse_with_no_name 引导我找到这个答案。
关系似乎丢失了,因为 Postgres 没有将 复制
search_path
到新数据库。如果您明确查看特定模式,则所有关系都在那里:因此,
search_path
需要在新数据库上明确设置:@Erwin Brandstetter 还提供了有关查看角色/数据库的 search_path 的更多信息。