PostgreSQL 数据库和 pgAdmin 4
PostgreSQL
PostgreSQL 数据库安装
PostgreSQL 数据库安装 (Ubuntu)
PostgreSQL Apt Repository 支持当前版本的 Ubuntu:
- kinetic (22.10, non-LTS)
- jammy (22.04, LTS)
- focal (20.04, LTS)
- bionic (18.04, LTS)
要使用 apt 存储库安装,请按照下列步骤操作:
# 创建存储库配置文件
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# 导入存储库签名密钥
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# 更新包列表
sudo apt-get update
# 安装最新版本的 PostgreSQ,如果你想要一个特定的版本,使用'postgresql-12'或类似的
sudo apt-get -y install postgresql
PostgreSQL 数据库其他系统安装
PostgreSQL Official Website Quick Links
PostgreSQL 数据库安装 (Mac平台)
PostgreSQL 数据库安装 (Windows平台) 和 Mac 安装相似,都是图形界面安装,不在赘述。
PostgreSQL 数据库快速使用入门
PostgreSQL 数据库安装完成后,会自动创建一个 postgres 用户
登录数据库
su - postgres # 切换到postgres用户
psql # 登录
访问数据库
列举数据库:\l
选择数据库:\c 数据库名
查看该某个库中的所有表:\dt
查看某个库中的某个表结构:\d 表名
查看某个库中某个表的记录:select * from apps limit 1;
显示字符集:\encoding
退出psgl:\q
参考
pgAdmin 4
pgAdmin 4 可以通过图形化界面来查看和管理 PostgreSQL 数据库。
安装前请确认 Apache2 状态正常,否则会出现未知的错误。
sudo systemctl status apache2
pgAdmin 4 安装
要使用 apt 存储库安装,请按照下列步骤操作:
#Setup the repository
# Install the public key for the repository (if not done previously):
curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg
# Create the repository configuration file:
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
# Install pgAdmin
# Install for both desktop and web modes:
sudo apt install pgadmin4
# Install for desktop mode only:
sudo apt install pgadmin4-desktop
# Install for web mode only:
sudo apt install pgadmin4-web
# Configure the webserver, if you installed pgadmin4-web:
sudo /usr/pgadmin4/bin/setup-web.sh
使用 pgAdmin 4 登录数据库