4. Cài đặt qua Home Brew
brew info postgresql
brew install postgresql
initdb /usr/local/var/postgres -E utf8
brew list
brew update
brew upgrade
Thư
mục
Brew
cài
postgresql
là
/usr/local/Cellar/postgresql/
• 9.3.1
• 9.3.2
• kiểm
tra
version
• cài
đặt
• Khởi
tạo
db
Lệnh
nâng
cấp
version
Thư
mục
chưa
file
cấu
hình
http://techmaster.vn
5. Thư mục chứa file cấu hình /usr/local/var/postgres
• postgresql.conf
• pg_hba.conf
ß
host-‐based
authentication,
quản
lý
cách
thức
truy
xuất
vào
Postgresql
http://techmaster.vn
6. Sửa pg_hba.conf để các client trong LAN kết nối vào Postgresql
# TYPE
DATABASE
USER
ADDRESS
METHOD
# "local" is for Unix domain socket connections only
local
all
all
trust
# IPv4 local connections:
host
all
all
127.0.0.1/32
trust
# IPv6 local connections:
host
all
all
::1/128
trust
#Bổ xung dòng này cho phép các client trong LAN kết nối
host
all
all
samenet
md5
http://techmaster.vn
8. Start – Stop Postgresql
pg_ctl -D /usr/local/var/postgres -l /usr/
local/var/postgres/server.log start
pg_ctl -D /usr/local/var/postgres stop -s -m
fast
Có
thể
phải
điều
chỉnh
lại
đường
dẫn
/usr/local/var/postgres
cho
phù
hợp
http://techmaster.vn
14. psql postgres
Nối
vào
cơ
sở
dữ
liệu
postgres
mặc
định
q
Thoát
?
Danh
sách
các
lệnh
quản
trị
Postgresql
l
Liệt
kê
các
database
List of databases
Name
|
Owner
| Encoding | Collate | Ctype |
Access privileges
-----------+------------+----------+---------+-------+--------------------------audiogara | TechMaster | UTF8
| C
| UTF-8 |
postgres | TechMaster | UTF8
| C
| UTF-8 |
template0 | TechMaster | UTF8
| C
| UTF-8 | =c/TechMaster
+
|
|
|
|
| TechMaster=CTc/TechMaster
template1 | TechMaster | UTF8
| C
| UTF-8 | =c/TechMaster
+
|
|
|
|
| TechMaster=CTc/TechMaster
http://techmaster.vn
15. Tạo cơ sở dữ liệu à tạo bảng
createdb demophalcon
psql demophalcon
create table users(id serial, name varchar(25));
insert into users(name) values('eric');
insert into users(name) values('tom');
select * from users;
id | name
----+-----1 | eric
2 | tom
(2 rows)
http://techmaster.vn
16. Có 2 loại lệnh
• Psql
command:
lệnh
Postgresql
để
quản
trị
CSDL
• SQL
command:
lệnh
SQL
là
để
định
nghĩa
thành
phần
trong
http://techmaster.vn
17. q
Thoát
?
Liệt
kê
danh
sách
các
lệnh
l
Liệt
kê
các
database
hiện
có
du
Liệt
kê
các
user
c postgres
Kết
nối
vào
cơ
sở
dữ
liệu
có
tên
là
postgres
conninfo
Thông
jn
kết
nối
{database,
user,
socket,
port}
dt
Liệt
kê
các
bảng
trong
cơ
sở
dữ
liệu
hiện
thời
dn
Liệt
kê
tất
cả
các
schema
dT
Liệt
kê
các
kiểu
dữ
liệu
được
định
nghĩa
mới
dv
Liệt
kê
các
view
Psql
commands
http://techmaster.vn