postgres基础知识

Posted kaka_jon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgres基础知识相关的知识,希望对你有一定的参考价值。

postgres是连接到具体的库:
   ./psql -U postgres  不指定库,默认就是用户名的同名库
   ./psql -d chat -U postgres  指定chat库
   
postgres登录权限配置文件是在数据目录下的pg_hba.conf     



\du: 查看用户
\dt: 查看表
\dn:查看schema
\c: 切换连接 如 \c postgres postgres 使用postgres用户连接到postgres数据库
\d: 查看数据库对象
\l:查看数据库

批量给某个用户授权示例
1. 管理员登录: ./psql  -U postgres

2. 创建用户: create user chat with password  ‘chatpasswd‘

3. 给用户授权:
   1. 先登录到需要授权的库下
    ./psql -d chat -U postgres

   2. 查看schema类型
    \d

   3. 根据schema授权
    grant all privileges on all tables in schema public to chat;
    
    grant usage,select on all sequences in shcema public to chat;

以上是关于postgres基础知识的主要内容,如果未能解决你的问题,请参考以下文章

为啥 SQLAlchemy Postgres ORM 需要 __init__(self) 作为声明性基础?

如何使用 SQLAlchemy Postgres ORM 的声明性基础动态创建具有列名和字典约束的表?

PG基础篇--逻辑结构管理(表继承分区表)

postgresql的安装与基础语法

postgresql的安装与基础语法

Postgres 错误:CASE 中不允许设置返回函数