如何在Ubuntu上安装PostgreSQL数据库:分步指南
#devops #postgres #database #ubuntu

在此博客中,我将演示如何在Ubuntu上安装PostgreSQL数据库。

Step #1:列出了已经安装的Postgres相关软件包

dpkg -l | grep postgres

例如:

 dpkg -l | grep postgres
ii  postgresql-12                              12.12-0ubuntu0.20.04.1              amd64        object-relational SQL database, version 12 server
ii  postgresql-client-12                       12.12-0ubuntu0.20.04.1              amd64        front-end programs for PostgreSQL 12
ii  postgresql-client-common                   214ubuntu0.1                        all          manager for multiple PostgreSQL client versions
ii  postgresql-common                          214ubuntu0.1                        all          PostgreSQL database-cluster manager

Step #2:如果不需要某些软件包,则运行“ sudo apt-get - purge remove ...”命令清除它们:

例如:

sudo apt-get --purge remove postgresql-12 postgresql-client-12

Step #3:创建文件存储库配置:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Step #4:导入存储库签名密钥:

wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null

Step #5:更新包列表:

sudo apt update

Step #6:安装最新版本的postgresql:

sudo apt install postgresql postgresql-client -y

Step #7:如果您想要特定版本,请使用“ Postgresql-13”或类似版本,而不是“ PostgreSql”:

sudo apt install postgresql-13 postgresql-client-13 -y

Step #8:检查状态

sudo systemctl status postgresql

Step #9:检查PostgreSQL客户端版本

psql --version

例如:

dmi@dmi-VirtualBox:~$ psql --version
psql (PostgreSQL) 13.9 (Ubuntu 13.9-1.pgdg20.04+1)
dmi@dmi-VirtualBox:~$

Step #10:检查PostgreSQL Server版本

sudo -u postgres psql
postgres=# select version();

例如:

postgres=# select version();

                                                              version                                                          
-----------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 13.9 (Ubuntu 13.9-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit
(1 row)