【PostgreSQL】- 1.1 在 Debian 12 上安装 PostgreSQL 15

官方说明参考

(原文 PostgreSQL:Linux 下载 (Debian)
默认情况下,PostgreSQL 在所有 Debian 版本中都可用。但是, Debians 的稳定版本“快照”了特定版本的 PostgreSQL 然后在该 Debian 版本的整个生命周期内都受支持。 PostgreSQL 项目还维护了一个 apt 存储库,所有 可用的 PostgreSQL。

PostgreSQL Apt 存储库

如果您的 Debian 版本中包含的版本不是您想要的版本, 您可以使用 PostgreSQL Apt 存储库。此存储库将集成 配合您的正常系统和补丁管理,并提供自动 在 PostgreSQL 的整个支持生命周期内更新所有受支持的 PostgreSQL 版本。
PostgreSQL apt 存储库支持当前支持的稳定版 Debian 的版本:

  • bookworm (12.x)
  • bullseye (11.x)
  • buster (10.x)
  • sid (unstable)

支持的体系结构:

  • amd64
  • arm64
  • i386 (buster and older)
  • ppc64el

要使用 apt 存储库,请按照下列步骤操作:

  # Create the file repository configuration:
  sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  
  # Import the repository signing key:
  wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  
  # Update the package lists:
  sudo apt-get update
  
  # Install the latest version of PostgreSQL.
  # If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
  sudo apt-get -y install postgresql

有关 apt 存储库的更多信息,包括对 frequent 的回答 如有疑问,请参阅 Wiki 上的 APT 页面。

分发中包含的内容

Debian 默认包含 PostgreSQL。安装 PostgreSQL Debian,使用 (或其他 apt-driving) 命令:apt-get

  ~# apt-get install postgresql-12

存储库包含许多不同的软件包,包括第三方插件。最常见和最重要的软件包是(根据需要替换版本号):

包名称说明
postgresql-client-12客户端库和客户端二进制文件
postgresql-12核心数据库服务器
libpq-dev用于 C 语言前端开发的库和头文件
postgresql-server-dev-12用于 C 语言后端开发的库和标头

安装 PostgreSQL 15 实践

参考上面的官方内容,进行安装实践。默认的 Debian 12 主存储库提供了 PostgreSQL 软件包。

检查 apt 仓库的 postgresql

  ~# apt-cache policy postgresql
  
  postgresql:
  Installed: (none)
  Candidate: 15+248
  Version table:
     15+248 500
        500 http://deb.debian.org/debian bookworm/main amd64 Packages
  

因此,要安装 PostgreSQL 15,可以运行以下命令:

  ~# apt install postgresql postgresql-contrib

注:
postgresql-contrib是一个软件包,它为PostgreSQL数据库系统提供了一些额外的特性。这些特性通常是作为扩展模块或额外的客户端/服务器应用程序来提供的。虽然它们是核心分发的一部分,但在默认情况下并不启用,因为它们要么提供特定的功能,要么被视为实验性质的,或者在某些情况下被用于提供已整合到PostgreSQL核心的功能的向后兼容性。
在安装postgresql-contrib包之后,您可以在PostgreSQL数据库中使用许多有用的扩展和工具,例如adminpackamcheckautoincbloombtree_ginbtree_gistcitextcubedblinkearthdistancefuzzystrmatchhllhstoreintaggintarrayisnltreeoid2namepageinspectpg_buffercachepg_freespacemappg_prewarmpg_stat_statementspg_visibilitypgcryptopgroongapgroutingpgstattupleplpgsqlpltclplv8postgispostgres_fdwsegsslinfotablefunctcntsm_system_rowstsm_system_timeunaccentuuid-ossp等等。这些扩展和工具提供了各种各样的功能,例如数据类型、函数、操作符、索引类型、全文搜索、空间数据库扩展等等。

更新系统

推荐操作:开始之前,确保系统是最新的,以最大程度地减少软件包冲突的可能性。通过执行以下命令来实现:

  ~# apt update 
  ~# apt upgrade

如果要指定具体版本号,需要先查看特定版本的 PostgreSQL 是否可用,可以直接查询该版本的软件包,如下所示:

  ~# apt-cache policy postgresql

则可能输出如:

  postgresql:
  Installed: (none)
  Candidate: 15+248
  Version table:
     15+248 500
        500 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 Packages

如何指定安装版本

首先查看库中的相关内容

  ~# apt-cache policy postgresql-15

则可能输出如:

  postgresql-15:
  Installed: (none)
  Candidate: 15.6-0+deb12u1
  Version table:
     15.6-0+deb12u1 500
        500 http://security.debian.org/debian-security bookworm-security/main amd64 Packages
     15.5-0+deb12u1 500
        500 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 Packages

将列出所有可用的postgresql-15软件包的版本。如果没有出现期望的版本,请运行 sudo apt update来更新信息。比如查找到版本列表中 15.6-0+deb12u1 候选,那么默认使用如下命令安装就会安装候选版本:

  ~# apt install postgresql-15

如果要指定版本,比如 15.5 版本:

  ~# apt install postgresql-15=15.5-0+deb12u1

现在实际安装最新稳定版本

~# apt install postgresql-15=15.6-0+deb12u1 postgresql-contrib

检查安装情况

完成后检查安装情况

  ~# dpkg -l | grep postgresql
  ii  postgresql-15                  15.6-0+deb12u1                 amd64        The World's Most Advanced Open Source Relational Database
  ii  postgresql-client-15           15.6-0+deb12u1                 amd64        front-end programs for PostgreSQL 15
  ii  postgresql-client-common       248                            all          manager for multiple PostgreSQL client versions
  ii  postgresql-common              248                            all          PostgreSQL database-cluster manager
  ii  postgresql-contrib             15+248                         all          additional facilities for PostgreSQL (supported version)

可以看到安装的相关软件包。

检查运行情况

  ~# systemctl status postgresql.service
  * postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; preset: enabled)
     Active: active (exited) since Wed 2024-03-27 00:30:26 CST; 8h ago
   Main PID: 4630 (code=exited, status=0/SUCCESS)
        CPU: 1ms
  
  systemd[1]: Starting postgresql.service - PostgreSQL RDBMS...
  systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.

注:显示exited,因为现在还没有初始化。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值