说明html
待补充git
《一天学会PostgreSQL应用开发与管理》阿里云社区sql
PostgreSQL中database、table、schema三者关系macos
PostgreSQL模式(架构)bash
macos安装yii
使用以下命令,会自动安装最新版,这里为9.5socket
sudo apt-get install postgresql
安装完成后,默认会:
(1)建立名为"postgres"的Linux用户
(2)建立名为"postgres"、不带密码的默认数据库帐号做为数据库管理员
(3)建立名为"postgres"的表
安装完成后的一些默认信息以下:
config /etc/postgresql/9.5/main
data /var/lib/postgresql/9.5/main
locale en_US.UTF-8
socket /var/run/postgresql
port 5432
安装完后会有PostgreSQL的客户端psql,经过 sudo -u postgres psql 进入,提示符变成: postgres=#
在这里可用执行SQL语句和psql的基本命令。可用的基本命令以下:
\password:设置密码 \q:退出 \h:查看SQL命令的解释,好比\h select。 \?:查看psql命令列表。 \l:--list databases \c [database_name]:链接其余数据库。 \d:列出当前数据库的全部表格。 \d [table_name]:列出某一张表格的结构。 \du:列出全部用户。 \e:打开文本编辑器。 \conninfo:列出当前数据库和链接的信息。 \dn --list schemas
brew install postgresql
遇到异常(没有受权)
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied error: could not lock config file .git/config: Permission denied ==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.6.3.sierra.bot Already downloaded: /Users/admin/Library/Caches/Homebrew/postgresql-9.6.3.sierra.bottle.tar.gz ==> Pouring postgresql-9.6.3.sierra.bottle.tar.gz Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink share/doc/postgresql /usr/local/share/doc is not writable.
受权、从新安装
sudo chown -R admin /usr/local/ brew reinstall postgresql
初始化数据库
initdb /usr/local/var/postgres -E utf8
开机启动
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
启动数据库
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
建立用户
createuser username -P --两次密码
建立DB
createdb dbname -O username -E UTF8 -e
登录
psql -U username -d dynamo -h localhost -p