pg创建数据库和用户并授权

postgres=# create database jycdb;
CREATE DATABASE
postgres=# create user jyc with password 'jyc';
CREATE ROLE
postgres=# revoke connect on database jycdb from public;
REVOKE
postgres=# grant all on database jycdb to jyc;
GRANT
postgres=# \c jycdb jyc
Password for user jyc: 
You are now connected to database "jycdb" as user "jyc".
jycdb=> \dt
Did not find any relations.
jycdb=> create table test (id int);
CREATE TABLE
jycdb=> insert into test values(1);
INSERT 0 1
jycdb=> select * from test;
 id 
----
  1
(1 row)

jycdb=> \dt
       List of relations
 Schema | Name | Type  | Owner 
--------+------+-------+-------
 public | test | table | jyc
(1 row)

jycdb=> drop table test;
DROP TABLE
jycdb=> \dt
Did not find any relations.
jycdb=> \l

相关参考:

postgresql数据库创建用户和授权_好记忆不如烂笔头abc的博客-CSDN博客_postgresql 数据库授权

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐