Install PostgreSQL 9.3.x

2014/08/12

Install PostgreSQL 9.3.x

安裝PostgreSQL lib

sudo apt-get install libpq-dev

安裝PostgreSQL

切到root

echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

切回使用者

sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-contrib-9.3

postgres設定

sudo -i -u postgres
psql

設定postgres密碼

alter user postgres with password 'your_password';

建立user

CREATE USER user_name WITH PASSWORD 'your_password';

建立db

CREATE DATABASE your_db_name;

設定登入權限

alter role user_name LOGIN;
GRANT ALL PRIVILEGES ON DATABASE your_db_name to user_name;

設定postgres強制密碼登入

sudo vim /etc/postgresql/9.3/main/pg_hba.conf

找到 # "local" is for Unix domain socket connections only 並修改成

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
host    all             all             0.0.0.0/0               trust

設定postgres允許外部登入

sudo vim /etc/postgresql/9.3/main/postgresql.conf

加入
listen_addresses = '*' # what IP address(es) to listen on;


上一篇 下一篇
blog comments powered by Disqus