淘先锋技术网

首页 1 2 3 4 5 6 7

安装与配置

安装

heyw@ubuntu:~/code/go/mps/MPS-backend/mps/map-service$ sudo apt-get update
heyw@ubuntu:~/code/go/mps/MPS-backend/mps/map-service$ sudo apt-get install postgresql

设置防火墙端口

heyw@ubuntu:~/code/go/mps/MPS-backend/mps/map-service$ sudo iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT

删除密码

heyw@ubuntu:~/code/go/mps/MPS-backend/mps/map-service$ sudo passwd -d postgres
[sudo] password for heyw: 
passwd: password expiry information changed.

设置密码

heyw@ubuntu:~/code/go/mps/MPS-backend/mps/map-service$ sudo -u postgres passwd
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

重启服务

heyw@ubuntu:~/code/go/mps/MPS-backend/mps/map-service$ /etc/init.d/postgresql restart
[ ok ] Restarting postgresql (via systemctl): postgresql.service.

本机使用

登录

heyw@ubuntu:~/code/go/mps/MPS-backend/mps/map-service$ psql -U postgres -h 127.0.0.1
Password for user postgres: 
psql (9.5.19)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=# 

查看所有的数据库

\l (l为L的缩写)

postgres=# \l

创建数据库

postgres=# create database testdb;
CREATE DATABASE

删除数据库

postgres=# drop database testdb;
DROP DATABASE

使用数据库

postgres=# \c testdb;
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
You are now connected to database "testdb" as user "postgres".
testdb=#

查看所有的表

testdb=# \d  

查看表结构

testdb=# \d point_dbs

退出

testdb=# \q