安装
1. 源代码编译安装也可以或者利用homebrew
这些源代码管理包也可以
2. 安装好后,运行如下命令创建一个数据库$ initdb /usr/local/var/postgres -E utf8
最后会输出如下信息:
Success. You can now start the database server using:
postgres -D /usr/local/var/postgres
or
pg_ctl -D /usr/local/var/postgres -l logfile start
3.利用上述命令启动postgresql server。
常见命令行工具
- 连接数据库(需要另开一个终端):
psql -U user -d dataname
- 列举数据库:
SELECT datname FROM pg_database;
或\l
- 切换数据库:
\c dbname
- 列举表:
\dt
- 查看表结构:
\d tbname
- sql语句语法是通用的。
- 更多帮助信息请输入:
help
- 退出数据库:
\q
详细的安装信息参见:http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/