Bash
切换到postgres用户
root@postgresql-1:~# su - postgres
进入到数据库里
postgres@postgresql-1:~$ psql
psql (14.2)
Type "help" for help.
postgres=#
查看命令帮助
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
解释:
\copyright for distribution terms
版权说明等
\h for help with SQL commands
查看服务器sql命令帮助信息
\? for help with psql commands
查看pgsql客户端命令。使用方法\?,如过想看所有的数据库\l
\g or terminate with semicolon to execute query
\q to quit
查看书库内的默认的所有的数据库
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
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
(3 rows)
解释:
postgres
默认数据库,类似mysql的mysql数据库
template0
template1
模板数据库,新创建的数据库会仿照这两个数据库来创建新的数据
template1和template0的区别主要有两点
1、template1 可以连接,template0 不可以连接
2、使用 template1 模板库建库时不可指定新的encoding 和locale,而 template0可以。
注意:template0和template1都不能被删除