如何在 Debian 11/10/9 上安装 PostgreSQL 13 |
PostgreSQL 是一个开源、强大、有弹性且容错的关系数据库管理系统,为许多关键任务应用程序提供支持。 PostgreSQL 数据库基于 POSTGRES 4.2。截至本文更新,PostgreSQL 的最新稳定版本是版本 13。PostgreSQL 13 的所有新功能、改进和错误修复报告均可在官方发布页面中找到。在本文中,我们将在 Debian 11/10/9 上安装 PostgreSQL 13。
以下是一些值得注意的新功能:
- B 树索引条目重复数据删除的改进 – 节省空间并提高性能
- 使用聚合或分区表的查询可以提高性能。
- 增量排序
- 使用扩展统计信息时更好的查询规划
- 索引的并行清理
在 Debian 11/10/9 上安装 PostgreSQL 13
如果您按照本文中概述的后续步骤进行操作,您应该可以在 Debian 10 上安装运行并正常工作的 PostgreSQL 13 | Debian 9 Linux 机器。
建议在继续之前更新您的系统和所有已安装的软件包。
sudo apt update && sudo apt -y upgrade
之后重新启动服务器。
sudo reboot
第 1 步:添加 PostgreSQL 13 存储库
在配置 APT 存储库之前,导入用于签名包的 GPG 密钥:
sudo apt update && sudo apt -y install gnupg2
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
导入 GPG 密钥后,将 PostgreSQL 存储库添加到您的 Debian 系统。
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list
Cat 创建的文件以检查其内容:
$ cat /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main
步骤 2:在 Debian 上安装 PostgreSQL 13
现在已成功添加存储库,更新软件包列表并在 Debian 11/10/9 Linux 计算机上安装 PostgreSQL 13。服务器可以在云中、本地硬件或任何其他有效的虚拟化环境中运行。
sudo apt update
最后在 Debian 11/10/9 上启动 PostgreSQL 13 的安装:
sudo apt -y install postgresql-13 postgresql-client-13
使用以下命令启动数据库服务器:
sudo pg_ctlcluster 13 main start
确认服务状态和正在使用的配置文件。
$ sudo pg_ctlcluster 13 main status
pg_ctl: server is running (PID: 4209)
/usr/lib/postgresql/13/bin/postgres "-D" "/var/lib/postgresql/13/main" "-c" "config_file=/etc/postgresql/13/main/postgresql.conf"
您还可以使用systemctl命令来检查服务的状态。
$ systemctl status [email
● [email - PostgreSQL Cluster 13-main
Loaded: loaded (/lib/systemd/system/[email ; enabled-runtime; vendor preset: enabled)
Active: active (running) since Fri 2023-05-26 17:49:01 UTC; 8s ago
Process: 15304 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 13-main start (code=exited, status=0/SUCCESS)
Main PID: 15309 (postgres)
Tasks: 7 (limit: 4553)
Memory: 17.0M
CPU: 235ms
CGroup: /system.slice/system-postgresql.slice/[email
├─15309 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf
├─15311 postgres: 13/main: checkpointer
├─15312 postgres: 13/main: background writer
├─15313 postgres: 13/main: walwriter
├─15314 postgres: 13/main: autovacuum launcher
├─15315 postgres: 13/main: stats collector
└─15316 postgres: 13/main: logical replication launcher
May 26 17:48:58 debian11 systemd[1]: Starting PostgreSQL Cluster 13-main...
May 26 17:49:01 debian11 systemd[1]: Started PostgreSQL Cluster 13-main.
步骤 3:访问 PostgreSQL shell
使用以下命令启动 PostgreSQL 提示符:
$ sudo su - postgres
postgres@debian:~$ psql
psql (13.11 (Debian 13.11-1.pgdg110+1))
Type "help" for help.
postgres=#
执行测试操作:
postgres=# exit
postgres@debian:~$ createuser c4geeks
postgres@debian:~$ createdb testdb -O c4geeks
postgres@debian:~$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | c4geeks | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
连接到数据库:
postgres@debian:~$ psql testdb
psql (13.11 (Debian 13.11-1.pgdg110+1))
Type "help" for help.
testdb=#
设置用户密码:
testdb=# alter user c4geeks with password 'StrongDBPassw0rd';
ALTER ROLE
删除数据库:
testdb=# \q
postgres@debian:~$ dropdb testdb
postgres@debian:~$ exit
logout
我希望您在 Debian 11/10/9 Linux 机器上使用 PostgreSQL 13 数据库服务器进行愉快的开发。
推荐书籍:
- 学习 PostgreSQL 数据库的最佳书籍
更多关于 Debian 的文章:
在 Debian 10 (Buster) 上安装和配置 Zabbix Server
在 UbuntuDebian 上安装 Oracle Java 14 (OpenJDK 14)
如何加入 Ubuntu/Debian 到 Active Directory (AD) 域