最近开始学习 PostgreSQL,准备慢慢告别 MySQL 了,这里整理收集了一些常用的控制台命令,方便查阅。

psql -U username -d dbname
psql dbname rolename
sudo -u username psql dbname
mysql: show databases
pgsql: \l 或 \list
mysql: use dbname
pgsql: \c dbname
mysql: show tables
pgsql: \d
mysql: show full columns from tablename
pgsql: \d tablename
mysql: describe tablename
pgsql: \d+ tablename
\d{t|i|s|v|S} [PATTERN] (add "+" for more detail)
mysql: quit 或 \q
pgsql: \q