如何在PostgreSQL中的新集群中添加数据库? [英] how to add database in a new cluster in postgreSQL?

查看:344
本文介绍了如何在PostgreSQL中的新集群中添加数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

sudo pg_createcluster -u=$USER --datadir=candisDatabase -l=candisDatabase/candis.psql.log 9.6 candisCluster

创建一个新数据库集群,指定目录为 $ USER帐户下的candisDatabase (即 rupav)。

to create a new database cluster with the specified directory as candisDatabase under the account $USER (which is 'rupav').

pg_lsclusters
Ver Cluster        Port Status Owner    Data directory               Log file
9.6 candisCluster2 5433 online   rupav    candisDatabase               candisDatabase/candis.psql.log
9.6 main           5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

集群已成功创建,并且能够运行/启动具有 pg_ctlcluster 9.6的新集群和服务器candisCluster2 candisCluster2成功启动

cluster is created successfully, and am able to run/start the new cluster and server candisCluster2 with pg_ctlcluster 9.6 candisCluster2 start successfully

以下是新集群的状态(使用 pg_ctlcluster 9.6 candisCluster2状态):

following is the status of the new cluster (using pg_ctlcluster 9.6 candisCluster2 status) :

/usr/lib/postgresql/9.6/bin/postgres "-D" "candisDatabase" "-c" "config_file=/etc/postgresql/9.6/candisCluster2/postgresql.conf"

现在服务器正在监听5433端口,如何我在给定的集群中添加创建角色,数据库和密码。默认情况下(在安装postgresql之后),我可以执行 sudo -u postgres psql 进入psql shell。

Now that server is listening on 5433 port, how can I add create role, database and password in the given cluster. By default (after postgresql installation) I can do sudo -u postgres psql to enter into the psql shell.

简而言之,我想在数据目录中指定所有表,如 candisDatabase ,该用户拥有的用户与 postgres

In short, I would like to have all my tables in the data directory specified, as candisDatabase which is owned by user different from postgres.

系统详细信息
我在 Ubuntu 17.10(Oracle VM,主机是Windows)上和PostgreSQL版本是9.6

System details: I am on 'Ubuntu 17.10 (Oracle VM, host being windows)' and postgresql version is 9.6

推荐答案

鉴于您指定的用户不想使用 postgres ,su改为您指定的用户。

Given that you specified user you don't want to su to postgres, su to the user you specified instead.

如果您只是这样做

psql "port=5433 dbname=postgres"

这篇关于如何在PostgreSQL中的新集群中添加数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆