Skip to content

Instantly share code, notes, and snippets.

@egoist
Last active May 14, 2016 14:37
Show Gist options
  • Save egoist/14d801ee46e4c2f281c5e4386aa503a4 to your computer and use it in GitHub Desktop.
Save egoist/14d801ee46e4c2f281c5e4386aa503a4 to your computer and use it in GitHub Desktop.
PostgreSQL 简明指南

安装

# 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

更多

http://postgresguide.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment