系統:centos6.4 安裝postgresql9.3html
(防火牆須要開啓5432端口)linux
yum install -y http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
yum install -y postgresql93-server postgresql93-contrib
更改默認安裝目錄爲/data/pgsql (可選,默認爲/var/lib/postgres)sql
vim /etc/init.d/postgresql-9.3 shell
更改數據庫
PGDATA=/data/pgsql/9.3/data
PGLOG=/data/pgsql/9.3/pgstartup.log
PGUPLOG=/data/pgsql/$PGMAJORVERSION/PGUPGRADE.log
service postgresql-9.3 initdb
chown postgres.postgres /data/pgsqlvim
vim /etc/passwd (更改postgres用戶家目錄)centos
更改bash
postgres:x:26:26:PostgreSQLServer:/data/pgsql:/bin/bash
#vim /data/pgsql/9.3/data/pg_hba.conf (容許如下網段網段ip登陸 )post
host all all 192.168.1.0/24 md5 host all all 192.168.2.0/24 md5
#vim /data/pgsql/9.3/data/postgresql.conf (監聽更改成*)spa
listen_addresses = '*'
#service postgresql-9.3 start (啓動數據庫)
#su - postgres
$createuser --help (查看新建用戶幫助) $createuser -s root 建立超級用戶root (可選) -bash-4.1$ psql psql (9.3.2) Type "help" for help. postgres=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication | {} root | Superuser, Create role, Create DB | {}
建立一個mydb庫 並賦予普通用戶test 對mydb 擁有全部權限
$createdb mydb (建立名字爲mydb的數據庫) $createuser test (建立普通用戶test) $psql postgres=# ALTER USER test with password 'test'; (爲test用戶更改密碼爲test) postgres=#grante all on database mydb TO test; postgres=# \q
參考: