简体   繁体   English

在多个Postgresql集群中创建角色

[英]Create roles in multiple postgresql cluster

I am quite new to PostgreSQL database. 我对PostgreSQL数据库很陌生。 We have started to use it just a week back as a part of our project requirements. 一周前,我们已开始使用它作为我们项目要求的一部分。 It took us a while to understand the architecture of the database. 我们花了一些时间来了解数据库的体系结构。

Having read many articles and documents. 阅读了许多文章和文档。 we have understood the following points: 我们了解以下几点:

  1. A database cluster in PostgreSQL is a collection of databases PostgreSQL中的数据库集群是数据库的集合
  2. With the default installation of the database, there is a default cluster called main which is activated by default 在数据库的默认安装中,有一个名为main的默认集群,默认情况下会被激活
  3. We can create and start a new cluster in the database by the following command: pg_createcluster 9.2 cluster1 -d /usr/local/cluster1 --start 我们可以通过以下命令在数据库中创建和启动新集群:pg_createcluster 9.2 cluster1 -d / usr / local / cluster1 --start
  4. Unlike users in MySQL, there are roles in postgresql that are cluster wide when created. 与MySQL中的用户不同,PostgreSQL中的角色在创建时在整个集群范围内。 ie, each cluster can have different roles. 即,每个集群可以具有不同的角色。 Roles are created using the following: createuser --interactive 使用以下命令创建角色:createuser --interactive

I have installed postgresql into my ubuntu system. 我已经在我的ubuntu系统中安装了postgresql。 I have also created 5 different clusters apart from the default 'main' cluster. 除了默认的“主”群集外,我还创建了5个不同的群集。 I can list them using pg_lsclusters command. 我可以使用pg_lsclusters命令列出它们。 I would want to now create different roles called 'test,test2,dev,dev2,live,live2' into each cluster. 我现在想在每个集群中创建称为“ test,test2,dev,dev2,live,live2”的不同角色。 When I create a role it doesn't ask me the cluster in which the role is supposed to be created. 创建角色时,它不会问我应该在其中创建角色的群集。

Also when performing any operation on the databases, how can I select the particular cluster into which I would want my commands to be executed. 同样,在对数据库执行任何操作时,如何选择要在其中执行命令的特定群集。

The name "cluster" in PostgreSQL is a bit misleading, as it is not really a cluster at all. PostgreSQL中的“集群”这个名称有点误导,因为它实际上根本不是集群。 A cluster is essentially a file system directory owned by the user running the PostgreSQL system. 集群本质上是运行PostgreSQL系统的用户所拥有的文件系统目录。 Under the directory are files and more directories that contain all the data pertaining to the cluster. 该目录下是文件和更多目录,其中包含与集群有关的所有数据。 A single cluster can hold multiple databases, all of whom are controlled by one running instance of PostgreSQL (this instance may also be referred to as the postmaster ). 一个集群可以容纳多个数据库,所有这些数据库都由一个运行中的PostgreSQL实例控制(该实例也称为postmaster )。 (The cluster can be distributed over different file systems using tablespaces, but that is besides the point here.) (可以使用表空间将群集分布在不同的文件系统上,但这还不重要。)

You can indeed have multiple clusters on a single system, but a PostgreSQL instance can only access a single cluster at a time, being specified at the command line when the postmaster is started. 实际上,您可以在一个系统上拥有多个集群,但是PostgreSQL实例一次只能访问一个集群,这是在启动postmaster时在命令行中指定的。 The other clusters can be utilized by other instances of PostgreSQL. PostgreSQL的其他实例可以利用其他集群。

Every cluster can contain multiple databases. 每个群集可以包含多个数据库。 A cluster can also have multiple role s (user, group), which are shared between all databases on the cluster; 集群还可以具有多个role (用户,组),它们在集群上的所有数据库之间共享; roles are never shared between clusters. 群集之间永不共享角色。 Nowadays in PostgreSQL you would use the command CREATE ROLE to create users and groups. 如今,在PostgreSQL中,您将使用CREATE ROLE命令创建用户和组。 They have identical permission structures and the basic difference is that users can log in to the database system and groups can not. 它们具有相同的权限结构,基本区别在于用户可以登录数据库系统而组不能登录。

Unless your requirements are really specific (ie you have to run a database on a specific server release version and another on another server release version) you should be able to get by with just a single cluster. 除非您的要求真的很具体(即,您必须在特定的服务器发行版上运行一个数据库,而在另一个服务器发行版上运行另一个数据库),则您应该只能使用一个集群。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM