直接使用 apt 来安装:
sudo apt update
sudo apt install postgresql postgresql-contrib
安装完成后,使用默认用户 postgres 连接默认数据库 postgres。
-
切换 Linux 用户为 postgres
sudo -iu postgres
-
登录 psql
psql
这样就打开了 postgres 数据库。
从上面的操作可以看出,安装 Postgres,自动就创建了:
- postgres 的Linux系统用户
- postgres 的数据库用户
- postgres 数据库
而且你使用数据库用户的登录psql时,会自动打开与用户同名的数据库。