gpt4 book ai didi

ruby-on-rails - PGError : ERROR: source database "template1" is being accessed by other users

转载 作者:行者123 更新时间:2023-11-29 11:13:07 24 4
gpt4 key购买 nike

我在使用 Postgresql 和 Rails 3 进行测试时遇到问题。

开发和生产数据库我都可以正常工作,但是当我运行 rakedb:test:prepare 等时,测试数据库会抛出以下错误。

PGError: ERROR: source database "template1" is being accessed by other users

更新

谷歌搜索,当使用 createdb 在 Postgres 中创建新数据库时,似乎应该使用 template0 而不是 template1 。在典型的“所以我会消除原因。但不是症状”时尚,我找到了 vendor/rails/railities/lib/task/databases.rake 并将第 109 行更改为:

createdb #{enc_option} \
-U "#{abcs["test"]["username"]}" \
-T template0 #{abcs["test"]["database"]}

但我真的不想这样做,因为我将 Rails 用作 GEM,有人知道其他解决方法或修复方法吗?

数据库.yml:

development:
adapter: postgresql
encoding: unicode
database: test1234_development
pool: 5
username: holden
password: postgres

test:
adapter: postgresql
encoding: unicode
database: test1234_test
pool: 5
username: holden
password: postgres

完整错误:

NOTICE: database "test1234_test" does not exist, skipping
PGError: ERROR: source database "template1" is being accessed by other users
DETAIL: There are 1 other session(s) using the database.
: CREATE DATABASE "test1234_test" ENCODING = 'unicode'

最佳答案

短篇小说:CREATE DATABASE 通过复制现有数据库来工作。如果另一个 session 连接到它,PostgreSQL 将不允许您复制数据库。如果其他用户正在访问 template1,CREATE DATABASE 将失败。

需要回答的问题:为什么其他session连接到template1?

template0和template1的区别

在您初始化数据库集群时,template0 和template1 是相同的。您希望通过使用 CREATE DATABASE 创建的每个数据库都可以使用的任何特定于位置的内容都应该进入 template1。因此,例如,如果您将过程语言 PL/python 添加到模板 1,您以后创建的每个数据库都将包含 PL/python。

数据库 template0 旨在成为“原始”模板。它应该只包含标准数据库对象——通过初始化集群创建的对象。作为“处女”模板,永远不要更改它。从来没有。

如果您需要指定编码和区域设置(整理),那么您可以通过复制 template0 来完成。你不能通过复制 template1 来做到这一点。

关于ruby-on-rails - PGError : ERROR: source database "template1" is being accessed by other users,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4977171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com