PostgreSQL创建库、表空间、角色、SCHEMA

本文详细介绍了如何在PostgreSQL中管理数据库,包括切换到postgres用户、修改用户密码、创建数据库、设置默认表空间、创建表空间、管理角色以及创建SCHEMA。建议在同一数据库下使用不同SCHEMA,而非分库,以方便管理。此外,还讲解了如何为角色分配权限和设置默认搜索路径。
摘要由CSDN通过智能技术生成

前置

sudo su - postgres // 切换到postgres用户
1、PostgreSQL会在安装阶段默认创建一个超级用户角色和一个database,均是postgres,
a、修改PostgreSQL数据库默认用户postgres的密码
sudo  passwd -d postgres //删除用户postgres的密码
sudo -u postgres passwd //设置用户postgres的密码
// 系统提示输入新的密码
New password:
Retype new password:
passwd: password updated successfully

 PG中可以采用分库的方式,即不同的模块创建不同的库;也可以使用同一个库下创建多个SCHEMA的方式;但一个数据连接只能访问一个库,不能跨库访问,即不同数据库之间不能关联查询,参考:
https://www.postgresql.org/docs/9.6/static/ddl-schemas.html
       A PostgreSQL database cluster contains one or more named databases. Users and groups of users are shared across the entire cluster, but no other data is shared across databases. Any given client connection to the server can access only the data in a single database, the one specified in the connection request.
      建议采用同一个库下创建不同SCHEMA的方式

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值