zoukankan      html  css  js  c++  java
  • Postgresql常用命令

    以下为刚接触postgresql常需要的数据库命令:

    1. 登录数据库                          psql -U 用户名 -W 数据库名      -h ip -p 端口  最后这两个参数可以有可以无,看使用情况
    2. 查看所有的用户                       select * from pg_user;
    3. 查看当前数据库下有的表                  select * from pg_tables;                 或者/dt
    4. 查看用户表权限                       select * from information_schema.table_privileges where grantee='用户名';
    5. 查看用户具有权限的表                   select * from information_schema.usage_privileges where grantee='用户名';
    6. 查看某表的具体字段情况                  d +表名
    7. 查看数据库下所有的schema                 dr
    8. 创建数据库                           createdb  数据库名称
    9. 删除数据库                           dropdb   数据库名
    10. 创建用户                            create user /role with password  '你要设置的密码'; 
                                        这里user和role的区别是: 用user默认创建的用户具有登录权限,用role无登录权限后面需要授权
    11. 修改密码                            ALTER ROLE 用户名 WITH PASSWORD '*'; 
    12. admin用户,INSERT INTO authors,提示没有表权限
    1. admindb=> INSERT INTO authors (name) VALUES ('Mo Yan'); 
    2. ERROR: permission denied for table authors
    1. postgres用户,授予表权限
    1. admindb=# GRANT ALL PRIVILEGES ON TABLE authors TO admin; 
    2. GRANT
    1. admin用户,INSERT INTO authors,提示没有sequence权限
    1. admindb=> INSERT INTO authors (name) VALUES ('Mo Yan'); 
    2. ERROR: permission denied for sequence authors_id_seq
    1. postgres用户,授予sequence权限
    1. admindb=# GRANT ALL PRIVILEGES ON SEQUENCE authors_id_seq TO admin; GRANT
  • 相关阅读:
    第二次,营造完整的人生(上)
    御风者(二)——狼王
    我的个人博客
    FTP 协议解析
    关于 Wireshark3 中 GeoIP 的问题
    CentOS8 NextCloud 私有云存储搭建
    Windows10 临时将线程绑定至指定CPU的方法
    CentOS8 yum/dnf 配置国内源(临时)
    Cknife流量分析
    samba + OPENldap 搭建文件共享服务器
  • 原文地址:https://www.cnblogs.com/lifei01/p/12436183.html
Copyright © 2011-2022 走看看