Create PostgreSQL database and User Account

After you finish the PostgreSQL installation, it will create a database named "postgres" and a database user "postgres" automatically, and it also create a Linux system user named "postgres"。
We will use the user "postgres" to generate the other user and new database.

Create Database and user account using command line

Create a new Linux system user named "reachnett".

sudo adduser reachnett

Switch to user "postgres"

sudo su - postgres

login PostgreSQL console using psql command.

psql

这时相当于系统用户postgres以同名数据库用户的身份,登录数据库,这是不用输入密码的。如果一切正常,系统提示符会变为"postgres=#",表示这时已经进入了数据库控制台。以下的命令都在控制台内完成。
创建数据库用户reachnett(刚才创建的是Linux系统用户),并设置密码。

CREATE USER reachnett WITH PASSWORD 'password';

创建用户数据库,这里为webtoprint,并指定所有者为reachnett。

CREATE DATABASE webtoprint OWNER reachnett;

将webtoprint数据库的所有权限都赋予reachnett,否则reachnett只能登录控制台,没有任何数据库操作权限。

GRANT ALL PRIVILEGES ON DATABASE webtoprint to reachnett;

最后,使用\q命令退出控制台(也可以直接按ctrl+D)。

\q

Use pgAdmin3 to connect to webtoprint database

pgAdmin3 Screenshot
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容