目录:
1.启动pgsl数据库
2.查看pgsql版本
1.启动pgsl数据库
[postgres@master ~]$ pg_ctl start [postgres@master data]$ pg_ctl -D /usr/local/pgsql/data start
2.查看pgsql版本
[postgres@master ~]$ pg_ctl --version
3.命令行登录数据库
psql -U username -d dbname -h hostip -p port [postgres@master ~]$ psql -U zhang -d mydb -h 127.0.0.1 -p 5432 psql (10.5) Type "help" for help. mydb=>
4.列出所有数据库
[postgres@master ~]$ psql -U zhang -d mydb -h 127.0.0.1 -p 5432 psql (10.5) Type "help" for help. mydb=> \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- mydb | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres test | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | (5 rows)
5.切换数据库
mydb=> \c test You are now connected to database "test" as user "zhang".
6.指定表的所有字段
mydb=> \d employees Table "public.employees" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- id | integer | | | age | integer | | | mydb=>