Henry
发布于 2024-01-31 / 48 阅读
0
0

PostgreSQL 数据库安装

背景简介

在 Debian 12 中安装 PostgreSQL 数据库。

环境配置

  1. 系统:Debian 6.1.66-1 (2023-12-09) x86_64 GNU/Linux

详细步骤

更新系统软件源

指令:apt update

myserver@pega23-db:~$ sudo apt update
[sudo] password for myserver: 
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm InRelease
Get:2 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates InRelease [52.1 kB]
Get:3 http://security.debian.org/debian-security bookworm-security InRelease [48.0 kB]         
Get:4 http://security.debian.org/debian-security bookworm-security/main Sources [73.3 kB]
Get:5 http://security.debian.org/debian-security bookworm-security/main amd64 Packages [135 kB]
Get:6 http://security.debian.org/debian-security bookworm-security/main Translation-en [80.3 kB]
Fetched 388 kB in 1s (276 kB/s)                             
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

 安装PostgreSQL数据库

指令:apt install postgresql-15

myserver@pega23-db:~$ sudo apt install postgresql-15

选择您想要的任何版本

配置PostgreSQL

设置 PostgreSQL 超级用户密码:passwd postgres

myserver@pega23-db:~$ sudo passwd postgres
New password: 
Retype new password: 
passwd: password updated successfully

启动 PostgresSQL

myserver@pega23-db:~$ sudo systemctl enable postgresql
Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable postgresql
myserver@pega23-db:~$ sudo systemctl start postgresql

查看数据库状态

myserver@pega23-db:~$ sudo systemctl enable postgresql
Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable postgresql
myserver@pega23-db:~$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; preset: enabled)
     Active: active (exited) since Tue 2024-01-30 10:49:28 HKT; 6min ago
   Main PID: 2453 (code=exited, status=0/SUCCESS)
        CPU: 1ms

Jan 30 10:49:28 pega23-db systemd[1]: Starting postgresql.service - PostgreSQL RDBMS...
Jan 30 10:49:28 pega23-db systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.

进入 PostgreSQL 超级用户

myserver@pega23-db:~$ sudo su - postgres
postgres@pega23-db:~$ 

连接数据库

postgres@pega23-db:~$ psql -U postgres
psql (15.5 (Debian 15.5-0+deb12u1))
Type "help" for help.

postgres=# 

至此,说明数据库安装已完成。


评论