PostgreSQL学习笔记---3 psql命令

前端之家收集整理的这篇文章主要介绍了PostgreSQL学习笔记---3 psql命令前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

psql是Postgresql命令行交互接口

先所以下postgres用户,在postgres编译安装完成后,会自动创建一个名为postgres的用户

首先切换到postgres用户
普通用户(可能)无法直接通过

su postgres

命令切换到postgres用户

需要先切换到root用户
在切换到postgres用户

su root
su postgres

接下来进入psql命令:

$ psql 
psql (9.5.4)
Type "help" for help.

postgres=# 

输入help

postgres=# help
You are using psql,the command-line interface to Postgresql.
Type:  \copyright for distribution terms
       \h for help with sql commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
postgres=# 

我们可以看到psql的介绍:
You are using psql,the command-line interface to Postgresql.

\l 命令可以列出所有的数据库

\l[+]   [PATTERN]      list databases

例如,我现在的数据库

postgres=# \l
                                     List of databases
     Name     |    Owner     | Encoding |   Collate   |    Ctype    |   Access privileges   
--------------+--------------+----------+-------------+-------------+-----------------------
 catmaid      | catmaid_user | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres     | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0    | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |              |          |             |             | postgres=CTc/postgres
 template1    | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |              |          |             |             | postgres=CTc/postgres
 test_catmaid | catmaid_user | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
(5 rows)

postgres=# 

\du 列出所有的用户

\du[+]  [PATTERN]      list roles

例如,我现在的所有用户

postgres=# \du
 List of roles
 Role name | Attributes | Member of --------------+------------------------------------------------------------+-----------
 catmaid_user | Superuser,Create DB | {}
 postgres | Superuser,Create role,Create DB,Replication,Bypass RLS | {}

postgres=#

猜你在找的Postgre SQL相关文章