PostgreSQL 修改设置数据库的默认用户以及权限.
1. 登录PG数据库.
psql -U postgres
界面效果为:
[root@centos76 ~]# psql -U postgres
psql (10.7)
Type "help" for help. postgres=#
其实这里面有一个主意事项. psql 的 命令执行 其实是在环境变量里面的
我这边使用的是rpm 方式安装的pg 数据库.
2. 简单说一下pgsql 的相关命令
使用反斜线作为命令前缀. 退出 \q
列出所有的数据库 \l
更改当前连接的数据库 \c
详细的帮助信息为:
postgres=# \?
General
\copyright show PostgreSQL usage and distribution terms
\crosstabview [COLUMNS] execute query and display results in crosstab
\errverbose show most recent error message at maximum verbosity
\g [FILE] or ; execute query (and send results to file or |pipe)
\gexec execute query, then execute each value in its result
\gset [PREFIX] execute query and store results in psql variables
\gx [FILE] as \g, but forces expanded output mode
\q quit psql
\watch [SEC] execute query every SEC seconds Help
\? [commands] show help on backslash commands
\? options show help on psql command-line options
\? variables show help on special variables
\h [NAME] help on syntax of SQL commands, * for all commands Query Buffer
\e [FILE] [LINE] edit the query buffer (or file) with external editor
\ef [FUNCNAME [LINE]] edit function definition with external editor
\ev [VIEWNAME [LINE]] edit view definition with external editor
\p show the contents of the query buffer
\r reset (clear) the query buffer
\s [FILE] display history or save it to file
\w FILE write query buffer to file Input/Output
\copy ... perform SQL COPY with data stream to the client host
\echo [STRING] write string to standard output
\i FILE execute commands from file
\ir FILE as \i, but relative to location of current script
\o [FILE] send all query results to file or |pipe
\qecho [STRING] write string to query output stream (see \o) Conditional
\if EXPR begin conditional block
\elif EXPR alternative within current conditional block
\else final alternative within current conditional block
\endif end conditional block Informational
(options: S = show system objects, + = additional detail)
\d[S+] list tables, views, and sequences
\d[S+] NAME describe table, view, sequence, or index
\da[S] [PATTERN] list aggregates
\dA[+] [PATTERN] list access methods
\db[+] [PATTERN] list tablespaces
\dc[S+] [PATTERN] list conversions
\dC[+] [PATTERN] list casts
\dd[S] [PATTERN] show object descriptions not displayed elsewhere
\dD[S+] [PATTERN] list domains
\ddp [PATTERN] list default privileges
\dE[S+] [PATTERN] list foreign tables
\det[+] [PATTERN] list foreign tables
\des[+] [PATTERN] list foreign servers
\deu[+] [PATTERN] list user mappings
\dew[+] [PATTERN] list foreign-data wrappers
\df[antw][S+] [PATRN] list [only agg/normal/trigger/window] functions
\dF[+] [PATTERN] list text search configurations
\dFd[+] [PATTERN] list text search dictionaries
\dFp[+] [PATTERN] list text search parsers
\dFt[+] [PATTERN] list text search templates
\dg[S+] [PATTERN] list roles
\di[S+] [PATTERN] list indexes
\dl list large objects, same as \lo_list
\dL[S+] [PATTERN] list procedural languages
\dm[S+] [PATTERN] list materialized views
\dn[S+] [PATTERN] list schemas
\do[S] [PATTERN] list operators
\dO[S+] [PATTERN] list collations
\dp [PATTERN] list table, view, and sequence access privileges
\drds [PATRN1 [PATRN2]] list per-database role settings
\dRp[+] [PATTERN] list replication publications
\dRs[+] [PATTERN] list replication subscriptions
\ds[S+] [PATTERN] list sequences
\dt[S+] [PATTERN] list tables
\dT[S+] [PATTERN] list data types
\du[S+] [PATTERN] list roles
\dv[S+] [PATTERN] list views
\dx[+] [PATTERN] list extensions
\dy [PATTERN] list event triggers
\l[+] [PATTERN] list databases
\sf[+] FUNCNAME show a function's definition
\sv[+] VIEWNAME show a view's definition
\z [PATTERN] same as \dp Formatting
\a toggle between unaligned and aligned output mode
\C [STRING] set table title, or unset if none
\f [STRING] show or set field separator for unaligned query output
\H toggle HTML output mode (currently off)
\pset [NAME [VALUE]] set table output option
(NAME := {border|columns|expanded|fieldsep|fieldsep_zero|
footer|format|linestyle|null|numericlocale|pager|
pager_min_lines|recordsep|recordsep_zero|tableattr|title|
tuples_only|unicode_border_linestyle|
unicode_column_linestyle|unicode_header_linestyle})
\t [on|off] show only rows (currently off)
\T [STRING] set HTML <table> tag attributes, or unset if none
\x [on|off|auto] toggle expanded output (currently off) Connection
\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
connect to new database (currently "postgres")
\conninfo display information about current connection
\encoding [ENCODING] show or set client encoding
\password [USERNAME] securely change the password for a user Operating System
\cd [DIR] change the current working directory
\setenv NAME [VALUE] set or unset environment variable
\timing [on|off] toggle timing of commands (currently off)
\! [COMMAND] execute command in shell or start interactive shell Variables
\prompt [TEXT] NAME prompt user to set internal variable
\set [NAME [VALUE]] set internal variable, or list all if no parameters
\unset NAME unset (delete) internal variable Large Objects
\lo_export LOBOID FILE
\lo_import FILE [COMMENT]
\lo_list
\lo_unlink LOBOID large object operations
3. 具体命令就是
展示所有数据库
\l
效果为:
gscloud=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------+---------------+----------+-------------+-------------+---------------------------------
GSCloud1903 | GSCloud1903 | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/GSCloud1903 +
| | | | | GSCloud1903=CTc/GSCloud1903
展示所有用户
\dg
gscloud=# \dg
List of roles
Role name | Attributes | Member of
---------------+------------------------------------------------------------+-----------
GSCloud1903 | Superuser, Replication | {}
创建用户
create role zhaobsh;
设置密码
alter role zhaobsh with password 'Test6530';
or
\password zhaobsh
修改属主
alter database "GSCloud1903" owner to zhaobsh;
增加权限
grant all on database "GSCloud1903" to zhaobsh;
设置是 supseruser 以及 登录权限
alter user zhaobsh superuser login
PostgreSQL 修改设置数据库的默认用户以及权限.的更多相关文章
- 修改PostgreSQL数据库的默认用户postgres的密码
有时候,忘记了postgresql 安装时默认用户postgres 的密码,怎么办呢? linux shell命令下面输入: sudo -u postgres psql (这样就可以直接登录进pos ...
- 修改PostgreSQL数据库的默认用户postgres的密码 并新建用户
1.忘记了postgresql 安装时默认用户postgres 的密码,怎么办呢? linux shell命令下面输入: sudo -u postgres psql (这样就可以直接登录进postg ...
- 修改jenkins启动的默认用户
# 背景 通过yum命令安装的jenkins,通过service jenkins去启动jenkins的话,默认的用户是jenkins,但jenkins这个用户是无法通过su切换过去的 ,在某些环节可能 ...
- 修改MySql数据库的默认时
MySql数据库创建后,默认的时区比东八区少了八个小时.如果Sql语句中使用到MySql的时间的话就会比正常时间少了八个小时.所以需要修改MySql的系统时区,使其显示的时间和我们现在的时间一致. 1 ...
- SQL Server 如何设置数据库的默认初始大小和自动增长大小
我们在SQL Server中新建数据库的时候,可以选择数据库文件及日志文件的初始大小.自动增长大小和最大大小,如下图所示: 可以通过设置更改数据库初始大小.自动增长大小和最大大小: 但是其实在SQL ...
- SqlServer2012,设置指定数据库对指定用户开放权限
REVOKE VIEW ANY DATABASE TO [public] --这个是取消数据库公开的权限,也就是除了sa角色外任何人都不能查看数据库 -- 现在用sa用户登录Use [要开放权限的数据 ...
- grant 权限 on 数据库对象 to 用户
grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant select on testdb.* to common_ ...
- Oracle user,role,profile常规操作--用户,权限,角色,配置文件
Oracle user,role,profile常规操作--用户,权限,角色,配置文件 1 权限查询 1查看所有用户 SQL> select username,account_status,lo ...
- MySQL用户与权限管理
执行mysql select 查询报错: SELECT command denied to user 'root'@'localhost' for table "xxx" 问题原因 ...
随机推荐
- scrapy 学习笔记2 数据持久化
前情提要:校花网爬取,并进行数据持久化 数据持久化操作 --编码流程: 1:数据解析 2:封装item 类 3: 将解析的数据存储到实例化好的item 对象中 4:提交item 5:管道接收item然 ...
- java获取windows和linux下本机ip通用方法
public InetAddress getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6) throws SocketE ...
- zabbix之自定义告警
zabbix支持内置的告警类型.email,sms,等 有时候需要自定义类型的. [其他微信,钉钉都差不多方式,只是脚本不一样] 自定义告警类型[自定义邮件] 编写自定义脚本,并测试成功. [脚本需要 ...
- 字典-Python基础前传(9)
(一)Python中为什么要有字典 jacky说科学存在的逻辑只有两个: 1.解释问题 2.解决问题 我们明白了科学的逻辑,我们理解任何的知识和技能,都是很简单的 之前jacky跟大家说list因为太 ...
- MySQL数据分析实战-朱元禄-专题视频课程
MySQL数据分析实战-496人已学习 课程介绍 本套课程由知名数据分析博主jacky老师录制,深入浅出讲解MySQL数据分析,从实战角度出发,帮助大家制胜职场!课程收益 1.学会 ...
- instr动态模糊查询
String sqlSearchtext = ""; if(!"".equals(model.getXzqhdm())&&model.getXz ...
- AtomicInteger原理
AtomicInteger的原理 java的并发原子包里面提供了很多可以进行原子操作的类,比如: AtomicInteger AtomicBoolean AtomicLong AtomicRefere ...
- kotlin中接口
使用interface关键字声明,一个类可以多实现,实现方法与类继承相同 接口中的属性和方法都是open的 package loaderman.demo interface myInterface{ ...
- iOS获取应用当前Caches目录路径以及当前日期
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSSt ...
- 用Keras搭建神经网络 简单模版(四)—— RNN Classifier 循环神经网络(手写数字图片识别)
# -*- coding: utf-8 -*- import numpy as np np.random.seed(1337) from keras.datasets import mnist fro ...