安装PG
mac
查看版本列表
brew search postgresql
安装
# 安装默认版本:14
brew install postgresql启动服务
brew services start postgresql@14
添加环境变量
echo 'export PATH="/opt/homebrew/opt/postgresql@14/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc登录
默认用户为与执行安装的用户同名,无密码。
psql -d postgres设置密码
ALTER USER <user> WITH PASSWORD 'your_password';centos
安装脚本
#!/bin/bash
# 设置国内镜像源
echo "设置国内镜像源..."
echo "exclude=postgresql*" >> /etc/yum.repos.d/CentOS-Base.repo
echo "[pgdg12]" > /etc/yum.repos.d/pgdg.repo
echo "name=PostgreSQL 12 for RHEL/CentOS 7 - x86_64" >> /etc/yum.repos.d/pgdg.repo
echo "baseurl=https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/12/redhat/rhel-7-x86_64" >> /etc/yum.repos.d/pgdg.repo
echo "enabled=1" >> /etc/yum.repos.d/pgdg.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/pgdg.repo
# 安装 PostgreSQL 12.3
echo "安装 PostgreSQL 12.3..."
yum install -y postgresql12-server
# 初始化数据库
echo "初始化数据库..."
/usr/pgsql-12/bin/postgresql-12-setup initdb
# 启动 PostgreSQL
echo "启动 PostgreSQL 12.3..."
systemctl start postgresql-12
# 设置开机自启动
echo "设置开机自启动..."
systemctl enable postgresql-12
echo "PostgreSQL 12.3 安装完成!"
安装后信息
通过上述脚本安装的 PostgreSQL,在 CentOS 7 上的默认安装位置如下:
安装文件:
PostgreSQL 二进制文件和可执行文件位于 /usr/pgsql-12/bin 目录下。
PostgreSQL 库文件位于 /usr/pgsql-12/lib 目录下。
PostgreSQL 插件文件位于 /usr/pgsql-12/share/extension 目录下。
配置文件:
主要的 PostgreSQL 配置文件 postgresql.conf 位于 /var/lib/pgsql/12/data 目录下。
pg_hba.conf 文件,用于配置客户端身份验证规则,也位于 /var/lib/pgsql/12/data 目录下。Last updated
Was this helpful?