PostgreSQL 修改设置数据库的默认用户以及权限.

1. 登录PG数据库.

psql -U postgres

界面效果为:

[[email protected] ~]# 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

原文地址:https://www.cnblogs.com/jinanxiaolaohu/p/11452472.html

时间: 2024-11-05 14:37:25

PostgreSQL 修改设置数据库的默认用户以及权限.的相关文章

修改PostgreSQL数据库的默认用户postgres的密码

有时候,忘记了postgresql 安装时默认用户postgres 的密码,怎么办呢? linux shell命令下面输入: sudo -u postgres psql  (这样就可以直接登录进postgres 了, 然后在里面可以进行添加用户,修改密码之类的,都不是问题了!!) -------------------------------------------------------------------------------------------------------------

Oracle 创建数据库、表用户及权限设置代码

--创建表空间和数据库文件及默认表空间大小create tablespace TableSpace_Test datafile 'E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DataBase_Test.DBF' size 200m; --设置数据库自动增长alter database datafile 'E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DataBase_Test.DBF' autoextend on; --创建用户cre

mysql设置数据库的默认编码

在安装mysql的时候如果没有选择编码方式的话,那么系统将默认选择latin1编码,在mysql的控制台的窗口中输入show variables like 'char%'可以查看到数据库系统的默认的编码集,如下: 我们可以看出系统的默认的编码是Latin1编码方式,Latin1是ISO-8859-1的别名,有些环境下写作Latin-1.ISO-8859-1编码是单字节编码,向下兼容ASCII.不支持中文编码,如果你在创建数据库或建表时没有明确指定编码的方式,那么数据库将采用默认的编码方式,而后你

数据库 之 MySQL用户和权限管理

1  概述 MySQL用户和权限管理 遵循最小权限授权法则,保证系统的安全性 本文主要讲解关于用户MySQL用户和权限管理的相关概念和操作 3  MySQL权限类别 库级别:对某些库拥有对应的权限 表级别:对某些表拥有相关权限 字段级别: 管理类:如super 程序类:如调用一个函数,或者执行一个函数 管理类: CREATE USER:创建用户账号 RELOAD:重新载入 LOCK TABLES:锁定表 REPLICATION CLIENT, REPLICATION SLAVE:复制功能 SHU

修改MySql数据库的默认时

MySql数据库创建后,默认的时区比东八区少了八个小时.如果Sql语句中使用到MySql的时间的话就会比正常时间少了八个小时.所以需要修改MySql的系统时区,使其显示的时间和我们现在的时间一致. 1)查看mysql系统时间 select now(); 2)设置时区更改为东八区 set global time_zone = '+8:00'; 3)刷新权限 flush privileges; 4)退出后重新登录,即可. 原文地址:https://www.cnblogs.com/endv/p/976

linux系统下修改mysql 数据库的root用户密码和开启远程用户

首先进入终端 1.输入以下命令显示mysql进程号 ps -A |grep -i mysql 2.输入以下命令kill掉上面显示的进程 kill -9 进程号1 进程号2 3.输入以下命令进入mysql安全模式 mysqld_safe --skip-grant-tables & 4.输入以下命令修改密码,注意末尾的分号必须有,每输入一行就回车 use mysql; update user set password = PASSWORD('你的密码') where user = 'root'; e

Oracle user,role,profile常规操作--用户,权限,角色,配置文件

1 权限查询 1查看所有用户 SQL> select username,account_status,lock_date,expiry_date,default_tablespace from dba_users; SQL> select * from all_users;--3 columns SQL> select * from user_users; 2查看用户系统权限 SQL> select * from dba_sys_privs; SQL> select * fr

(转)Mysql用户与权限管理

========对于ROOT用户的密码操作(更改用户密码)======== 刚刚安装完的Mysql,只一有个root用户,密码为空,而且只能在本机登录! 为root加上密码xxx123:./bin/mysqladmin -u root password xxx123或写成./bin/mysqladmin -uroot password xxx123 加下密码之后,在本进行进入mysql:./bin/mysql -uroot -p 更改root的密码由xxx123改为yy1234:./bin/my

MongoDB用户及权限管理(二):用户管理

一.创建管理员账号 下面开始创建一个帐号,该账号需要有grant权限,即:账号管理的授权权限.注意一点,帐号是跟着库走的,所以在指定库里授权,必须也在指定库里验证(auth). > use admin switched to db admin > db.createUser( { user:  "dba", pwd:  "dba", roles:  [ { role: "userAdminAnyDatabase", db: "