標籤:ted 設定 ext com 初始化 unit .gz 5.6 允許
postgresql安裝
--------------------
二進位安裝:
wget https://get.enterprisedb.com/postgresql/postgresql-9.5.6-1-linux-x64-binaries.tar.gz
tar xf postgresql-9.5.6-1-linux-x64-binaries.tar.gz -C /usr/local/
useradd postgres
mkdir -p /data/postgresql/{data,log}
chown -R postgres.postgres /data/postgresql/
初始化資料庫:
su postgres
cd /usr/local/pgsql/bin
./initdb -E utf8 -D /data/postgresql/data/
啟動指令碼:
vi /etc/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
Environment=PGSTARTTIMEOUT=270
Environment=PGDATA=/data/postgresql/data
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
TimeoutSec=300
[Install]
WantedBy=multi-user.target
啟動關閉和開機啟動:
systemctl daemon-reload
systemctl enable postgresql
systemctl start postgresql
systemctl stop postgresql
systemctl restart postgresql
postgresql配置
-----------------------
設定檔:預設在data目錄下
主設定檔:/data/postgresql/data/postgresql.conf
允許遠端存取-> listen_addresses = ‘localhost,192.168.30.3‘
許可權控制檔案:/data/postgresql/data/pg_hba.conf
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 192.168.30.2/32 md5
# IPv6 local connections:
host all all ::1/128 md5
重啟使設定檔生效:systemctl reload postgresql
註:如果還沒有設定postgres使用者的密碼,需要先把本地設定為trust:
local all all trust
然後設定密碼,再修改回來
psql -U postgres
postgres-# ALTER USER postgres PASSWORD ‘xxxx‘;
建立資料庫和授權
----------------------
建立使用者:postgres=# create user fishing password ‘xxxx‘
建立資料庫:create database fishing owner fishing;
退出資料庫,使用建立使用者登入建立的資料庫:psql -U fishing -d fishing
測試資料庫許可權:
1. 建立一張表
create table test(
id int primary key not null,
name text not null
);
2. 查看錶
fishing-> \dt
List of relations
Schema | Name | Type | Owner
--------+------+-------+---------
public | test | table | fishing
(1 row)
3. 向表中插入資料
insert into test(id,name) values (1,‘aa‘);
select * from test;
4. 刪除測試表
drop table test;
ubuntu 16.04.1 LTS postgresql安裝配置