PostgreSQL学习记录

一、安装

使用 docker 安装:

$ docker pull postgres:alpine

二、启动

起 docker 容器:

$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres:alpine

默认用户:postgres

默认密码:mysecretpassword

或者通过 psql,验证不成功:

$ docker run -it --rm --network some-network postgres:alpine psql -h some-postgres -U postgres:alpine

报错:

docker: Error response from daemon: network some-network not found.

使用容器连接:

$ docker run --rm -t -i --link some-postgres:pg postgres:alpine bash

在客户端 docker run 中直接使用 -link remote_name:local_alias 使容器连接到另一个容器端口。比如上面的例子就是使容器 some-postgres 连接到另一个容器 pg。

然后,通过 psql

$ psql -h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT -d postgres -U postgres --password

注意用户要是之前的默认用户 postgres

然后会出现输入密码,输入之前设置的默认密码:mysecretpassword

以下界面表示成功连接到 PostgreSQL:

psql (13.3)
Type "help" for help.

postgres=#

三、PSQL 操作数据库

psql命令

Object Type All Privileges Default PUBLIC Privileges psql Command
DATABASE CTc Tc \l
DOMAIN U U \dD+
FUNCTION or PROCEDURE X X \df+
FOREIGN DATA WRAPPER U none \dew+
FOREIGN SERVER U none \des+
LANGUAGE U U \dL+
LARGE OBJECT rw none
SCHEMA UC none \dn+
SEQUENCE rwU none \dp
TABLE (and table-like objects) arwdDxt none \dp
Table column arwx none \dp
TABLESPACE C none \db+
TYPE U U \dT+
中文补充
操作 命令
查看所有数据库 # \l
切换数据库 # \c dbname
查看当前数据库中的所有表 # \d
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wonz

创作不易,一块就行。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值