Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
The community reviewed whether to reopen this question 2 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
PostgreSQL“架构”与 MySQL“数据库”大致相同。 在 PostgreSQL 安装上安装多个数据库可能会出现问题; 拥有许多模式将毫无问题。 因此,您肯定希望使用一个数据库和该数据库中的多个模式。
A PostgreSQL "schema" is roughly the same as a MySQL "database". Having many databases on a PostgreSQL installation can get problematic; having many schemas will work with no trouble. So you definitely want to go with one database and multiple schemas within that database.
我建议不要接受接受的答案 - 多个数据库而不是多个架构,原因如下:
I would recommend against accepted answer - multiple databases instead of multiple schemas for this set of reasons:
当然,我会采用一数据库多模式方法。 这使我可以转储所有数据库,但可以通过多种方式非常轻松地仅恢复一个数据库:
否则,谷歌搜索我发现没有自动过程来复制模式(使用一个作为模板),但许多人建议这样做:
我已经用 Python 编写了两行来做到这一点; 我希望他们可以帮助某人(在 2 秒内编写代码,不要在生产中使用它):
Definitely, I'll go for the one-db-many-schemas approach. This allows me to dump all the database, but restore just one very easily, in many ways:
Otherwise, googling around I've seen that there is no auto-procedure to duplicate a schema (using one as a template), but many suggest this way:
I've written two rows in Python to do that; I hope they can help someone (in-2-seconds-written-code, don’t use it in production):
我想说,使用多个数据库和多个模式:)
PostgreSQL 中的模式很像 Oracle 中的包,如果您熟悉这些的话。 数据库旨在区分整个数据集,而模式更像是数据实体。
例如,您可以为整个应用程序使用一个数据库,其模式为“UserManagement”、“LongTermStorage”等。 然后,“UserManagement”将包含“User”表,以及用户管理所需的所有存储过程、触发器、序列等。
数据库是整个程序,模式是组件。
I would say, go with multiple databases AND multiple schemas :)
Schemas in PostgreSQL are a lot like packages in Oracle, in case you are familiar with those. Databases are meant to differentiate between entire sets of data, while schemas are more like data entities.
For instance, you could have one database for an entire application with the schemas "UserManagement", "LongTermStorage" and so on. "UserManagement" would then contain the "User" table, as well as all stored procedures, triggers, sequences, etc. that are needed for the user management.
Databases are entire programs, schemas are components.
在 PostgreSQL 上下文中,我建议使用一个具有多个模式的数据库,因为您可以(例如)跨模式进行 UNION ALL,但不能跨数据库。 因此,一个数据库实际上与另一个数据库完全隔离,而模式并不与同一数据库中的其他模式隔离。
如果您出于某种原因将来必须跨模式整合数据,那么在多个模式上执行此操作将很容易。 对于多个数据库,您将需要多个数据库连接,并通过应用程序逻辑“手动”从每个数据库收集和合并数据。
后者在某些情况下具有优势,但对于主要部分,我认为单数据库多模式方法更有用。
In a PostgreSQL context I recommend to use one db with multiple schemas, as you can (e.g.) UNION ALL across schemas, but not across databases. For that reason, a database is really completely insulated from another database while schemas are not insulated from other schemas within the same database.
If you -for some reason- have to consolidate data across schemas in the future, it will be easy to do this over multiple schemas. With multiple databases you would need multiple db-connections and collect and merge the data from each database "manually" by application logic.
The latter have advantages in some cases, but for the major part I think the one-database-multiple-schemas approach is more useful.
许多模式应该比许多数据库更轻量级,尽管我找不到证实这一点的参考文献。
但是,如果您确实想让事情保持非常独立(而不是重构 Web 应用程序以便将“客户”列添加到您的表中),您可能仍然希望使用单独的数据库:我断言您可以更轻松地恢复以这种方式访问特定客户的数据库,而不会干扰其他客户。
A number of schemas should be more lightweight than a number of databases, although I cannot find a reference which confirms this.
But if you really want to keep things very separate (instead of refactoring the web application so that a "customer" column is added to your tables), you may still want to use separate databases: I assert that you can more easily make restores of a particular customer's database this way -- without disturbing the other customers.
这取决于系统的可用性和连接性的设计方式。 这些数据库中存储的数据是什么。如果它们是链接数据,则它们可以保存在单个数据库实例上,但如果它们部分链接并且在一个系统关闭时可以部分运行,那么它们必须位于不同的实例上。
详细说明:-
1) 当您使用一个数据库实例并且使用多个数据库时,您会遇到这样的问题:如果您的连接中断(由于系统崩溃或 mysql 服务器宕机),所有数据库都会恢复正常同一实例上的应用程序也已关闭,因此您的所有应用程序都会受到影响。
2)当您为每个数据库分离数据库实例时,如果任何一个数据库系统发生故障,您的其他应用程序不会受到影响。因此其他应用程序只能运行依赖于故障数据库受影响的应用程序。
另外,在这两种情况下,我认为您还必须使用复制机制,以便可以在从数据库上完成负载平衡。
It depends on how the availability and connectivity of your system is designed. What are the data that are stored in these Databases.If they are linked data, there they can be kept on single DB instance but if they are partially linked and can run partially if one system is down then it must be on different instances.
Detailed explanation:-
1) When you use one DB instance and in that you use multiple databases, then you are caught up with the issue that if your connection goes down(due to system crash or mysql server is down),all Databases as they are on same instance are also down, so all your applications are impacted.
2) When you separate DB instance for each Database,then if any one Database system is down,your other applications doesn't have impact.So other application can run only the application which depends on down DB is impacted.
Also,in both the cases i think you must also use replication mechanism so that load balancing can be done on slave Databases.