我正在尝试根据 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.
Run Code Online (Sandbox Code Playgroud)
我使用命令行得到同样的结果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.
Run Code Online (Sandbox Code Playgroud)
为什么我看不到该数据库的完整副本?
背景- 这是一个开发服务器,我可以在其中断开连接来制作副本。我想要的只是一个本地副本,以便在使用 Perl 框架开发/测试数据库架构更改时轻松回滚我想要的只是一个本地副本,以便在使用 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)
Run Code Online (Sandbox Code Playgroud)
感谢@a_horse_with_no_name 引导我找到这个答案。
这些关系似乎丢失了,因为 Postgres 不会将其复制search_path
到新数据库。如果您明确查看特定模式,所有关系都在那里:
\dt <schema>.*
Run Code Online (Sandbox Code Playgroud)
因此,search_path
需要在新数据库上显式设置:
ALTER DATABASE gcis_rollback2 SET SEARCH_PATH gcis_metadata, public
Run Code Online (Sandbox Code Playgroud)
@Erwin Brandstetter 还提供了有关查看角色/数据库的 search_path 的更多信息。
归档时间: |
|
查看次数: |
2390 次 |
最近记录: |