如何在特定表空间中设置 django 和 postgres 数据库?
您所期望的::
settings.py
DATABASES = {
'default': {
'NAME': 'db_name',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'host',
'PORT': '5432',
'DEFAULT_TABLESPACE': 'tablespace-name',
}
}
当我使用 DEFAULT_TABLESPACE 时,我希望使用此默认表空间授予访问权限。但我在那里用什么并不重要。另外,如果我在模型元类中显式使用 db_tablespace,据我所知,它不会执行任何操作。
我也尝试过不同的用户,但即使用户 postgres 也不起作用。如果我定义 db_table = "tablespace.tablename",它也不起作用。
将起作用的 SQL:
select count(*) from schemaname.tablename
我对数据库进行了备份并在本地恢复它,而没有创建表空间。它导入良好并忽略表空间。然后就可以了。
如何使用带表空间的 postgres 配置 Django?或者模式名称?其实我对这方面不太懂,所以希望大家能帮帮我。
另请参阅: https://docs.djangoproject.com/en/dev/topics /db/tablespaces/
使用 Django 1.3.1、postgresql 8.4、psycopg2
更新:
使用表空间时似乎没有选择“默认架构”。我尝试了一些测试,以下是使用 ./manage.py dbshell 的结果:
这确实适用于没有表空间的数据库,但不适用于有表空间的数据库:
select * from parameter;
这确实适用于两个数据库:
select * from tablespace.parameter;
不幸的是,选项“DATABASE_SCHEMA数据库设置中的“不起作用,模型元对象中的“db_schema”也不起作用。所以现在问题有点清楚了。有人有解决办法吗?
What you'd expect::
settings.py
DATABASES = {
'default': {
'NAME': 'db_name',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'host',
'PORT': '5432',
'DEFAULT_TABLESPACE': 'tablespace-name',
}
}
When I use DEFAULT_TABLESPACE, I would expect that the access will be granted using this default tablespace. But it doesn't matter what I use there. Also, if I explicitly use db_tablespace in a models Meta class, it doesn't do anything as far I can tell.
I've tried different users as well, but even user postgres does not work. If I define db_table = "tablespace.tablename", it also does not work.
The SQL that will work:
select count(*) from schemaname.tablename
I made a backup of the database and restored it locally, without creating the tablespace. It imports well and ignores the tablespace. Then it just works.
How do I configure Django with postgres with tablespaces? Or schemaname?? Actually I don't understand anything of this, so I hope you guys can help me out.
See also: https://docs.djangoproject.com/en/dev/topics/db/tablespaces/
Using Django 1.3.1, postgresql 8.4, psycopg2
Update:
It seems that the "default schema" is not picked up when using tablespaces. I tried out some tests and here are the results using ./manage.py dbshell:
This does work on my database without tablespaces, but does not work on the database with tablespaces:
select * from parameter;
This does work on both databases:
select * from tablespace.parameter;
Unfortunately, the option "DATABASE_SCHEMA" in the db settings does not work, neither does "db_schema" in the models Meta object. So the problem is a bit clearer now. Does anybody have a solution to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模式和表空间是两个不同的东西。
schema 本质上是一个命名空间。 表空间是文件系统中的一个位置。模式是逻辑事物;表空间是物理的东西。
如果您尝试将命名空间中的一堆相关表(可能还有其他命名对象)组合在一起,则需要一个架构。
如果您尝试通过将索引放在快速 SSD 磁盘(与表、视图等不同的磁盘)上来提高速度,那么您需要一个表空间。
A schema and a tablespace are two different things.
A schema is essentially a namespace. A tablespace is a place in the filesystem. Schemas are logical things; tablespaces are physical things.
If you're trying to group together a bunch of related tables (and possibly other named objects) in a namespace, you want a schema.
If you're trying to increase speed by putting indexes on a fast SSD disk--a different disk than the tables, views, etc.--you want a tablespace.