linux 命令行连接 PostgreSQL

linux下连接PostgresSQL的命令行工具是 “psql”

在这个页面获取下载安装的命令行:https://www.postgresql.org/download/linux/redhat/

头两行都要运行,先装repo,再装postgresql-sever

安装后就可以运行psql。

psql连接语句示例:(启用SSL)

psql "sslmode=verify-full sslrootcert=/path/of/cert host=host.ip dbname=dbname user=username@host"

当连接Azure PaaS的 Postgresql 时,证书可以去这里下: 

https://dl.cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem

参考:https://docs.azure.cn/zh-cn/postgresql/concepts-ssl-connection-security

 

PostgreSQL 命令:

\l: 显示所有表

\c dbname: 类似use db

1、相当于mysql的show databases;
select datname from pg_database;

2、相当于mysql的show tables;
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
public 是默认的schema的名字

3、相当于mysql的describe table_name;
SELECT column_name FROM information_schema.columns WHERE table_name ='table_name';
'table_name'是要查询的表的名字

 
posted @ 2020-12-01 18:33  爱知菜  阅读(343)  评论(0编辑  收藏  举报