postgres的使用命令

1、更新源

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm -y  

2、查看pg源

yum list | grep postgresql

3、安装pg

yum install postgresql10-contrib postgresql10-server -y

4、初始化数据库

Postgresql安装目录是/usr/pgsql-10,而Postgresql的数据目录是/var/lib/pgsql/版本号/data目录

/usr/pgsql-10/bin/postgresql-10-setup initdb

5、启动pg

service postgresql start

6、进入pg

su - postgres
psql

7、常用命令

password           设置密码
q                  退出
h                  查看SQL命令的解释,比如h select
?                  查看psql命令列表
l                  列出所有数据库
c [database_name]  连接其他数据库
d                  列出当前数据库的所有表格
d [table_name]     列出某一张表格的结构
x                  对数据做展开操作
du                 列出所有用户
原文地址:https://www.cnblogs.com/dj3839/p/9680889.html