官网:
Bash
https://www.postgresql.org/
配置ubuntu源等信息
Bash
https://www.postgresql.org/download/linux/ubuntu/
配置信息可以写成脚本安装
Bash
vim install_PostgreSQL.sh
写入一下内容,这里的内容根据官网的内容来复制,版本会更新
Bash
# Import the repository signing key:
sudo apt install curl ca-certificates
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
# Create the repository configuration file:
sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Update the package lists:
sudo apt update
# Install the latest version of PostgreSQL:
# If you want a specific version, use 'postgresql-16' or similar instead of 'postgresql'
sudo apt -y install postgresql
安装好以后进入到postgres用户里面初始化数据库
Bash
su - postgres
初始化数据库,我这里是16的版本,如果你是17或者更新的版本,把版本号改一下
Bash
/usr/lib/postgresql/16/bin/initdb -D /var/lib/postgresql/data
启动数据库,我这里是16的版本,如果你是17或者更新的版本,把版本号改一下
Bash
/usr/lib/postgresql/16/bin/pg_ctl -D /var/lib/postgresql/data -l logfile start
查看版本号
Bash
postgres@zookeeper-1:~$ psql -c "SELECT version();"
version
-----------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 16.3 (Ubuntu 16.3-1.pgdg22.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
(1 row)