PostgreSQL的使用

安装与配置

安装

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
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值