redhat7.0安装postgresql

安装命令

sudo yum install postgresql-server
  • 查看安装的包
sudo yum list postgres* 

postgresql.x86_64
postgresql-contrib.x86_64
postgresql-libs.x86_64    
postgresql-server.x86_64

sudo su -c " PGSETUP_INITDB_OPTIONS='-U postgres -E UTF8 --locale=zh_CN.UTF-8' postgresql-setup  initdb"

Initializing database ... OK

sudo systemctl enable postgresql

/etc/systemd/system/multi-user.target.wants/postgresql.service

sudo systemctl start postgresql
  • 切换账号,登录psql
sudo su postgres
psql

至此, postgresql安装完成!

  • 使用密码认证,在初始化时考虑加入: PGSETUP_INITDB_OPTIONS = '-auth-host=md5 …' 或者修改
  sudo sed -r -i 's/^(host.*)(ident)/\1md5/g'  /var/lib/pgsql/data/pg_hba.conf

数据库配置

  • 登录数据库
sudo su postgres
psql
  • 设置密码、账号
postgres=# \password postgres
postgres=# create user keke_zhaokk with password '密码';
postgres=# create database exampledb owner keke_zhaokk;
postgres=# grant all privileges on database exampledb to keke_zhaokk;
postgres=# \q
  • 用账号密码登录
psql -U postgres -h 127.0.0.1 -p 5432
psql -U keke_zhaokk  -d exampledb -h 127.0.0.1 -p 5432
posted @ 2016-12-26 20:18  bregman  阅读(1010)  评论(0编辑  收藏  举报