1, 添加库:
sudo add-apt-repository “deb https://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main”
2, 安装
sudo apt-get update
sudo apt-get install postgresql-9.6
sudo apt-get install postgresql-9.6-postgis-2.4
sudo apt-get install postgresql-9.6-pgroutintg
3, 修改密码
sudo passwd postgres
Enter new UNIX password:****
Retype new UNIX password:****
passwd: password updated successfully
4, 启动服务
sudo service postgresql start
5, 切换到默认用户postgres
su postgres
Password:****
6, 创建数据库
createdb mytestdb
7, 新建/删除用户
createuser examplerole
—-
dropuser examplerole
8, 使用psql工具
psql mytestdb
将看到下面的结果, 中这里可以执行各种sql语句
psql (9.6.6)
Type “help” for help.
mytestdb=#
9, 修改用户密码:
ALTER USER postgres WITH PASSWORD ‘***’;
10, (psql) 建一个表
CREATE TABLE employees (employee_id int, first_name varchar, last_name varchar);
INSERT INTO employees VALUES (1, ‘John’, ‘Doe’);
SELECT * FROM employees;
结果:
employee_id | first_name | last_name
————-+————+———–
1 | John | Doe
(1 row)