# ubuntu
$ sudo apt-get install postgresql$ sudo su - postgres
$ psql$ CREATE USER username WITH PASSWORD 'password'$ CREATE DATABASE exampledb OWNER username;赋予数据库读写权限给 username:
$ GRANT ALL PRIVILEGES ON DATABASE exampledb to username;当存在和当前 linux 系统用户名相同的 pgsql 用户和数据库时可以省略该部分:
$ psql -U username -d exampledb -h 127.0.0.1 -p 5432\ls : 列出所有数据库
\du : 列出所有用户
\d : 列出当前数据库所有表
\d [tableName] : 列出某个表的结构
\? : 列出命令行帮助
当不在控制台内操作时可以将 \ 改成 - 执行,比如 psql -ls。