how to add database in a new cluster in postgreSQL?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-25 10:20:31

问题


I am using

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

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

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

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"

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.

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.

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


回答1:


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

if it's you just do

psql "port=5433 dbname=postgres"


来源:https://stackoverflow.com/questions/51313244/how-to-add-database-in-a-new-cluster-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!