- 工信部备案号 滇ICP备05000110号-1
- 滇公网安备53011102001527号
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
- CN域名投诉举报处理平台:电话:010-58813000、邮箱:service@cnnic.cn
欢迎来到8455线路检测中心技术小课堂,每天分享一个技术小知识。
PostgreSQL 是一个功能强大的开源关系型数据库系统,以其可靠性、功能完整性和性能而闻名。本文详细介绍在 Ubuntu 和 Debian 系统中安装、配置和管理 PostgreSQL 的完整流程。
# 更新包列表
sudo apt update
# 升级已安装的包
sudo apt upgrade -y
# 安装必要的依赖
sudo apt install curl wget gnupg2 lsb-release ca-certificates -y
# 检查是否已安装 PostgreSQL
which psql
psql --version
# 检查服务状态
sudo systemctl status postgresql
sudo systemctl status postgresql-14
# 如果已安装旧版本,先备份数据然后卸载
sudo systemctl stop postgresql
sudo apt purge postgresql-* -y
sudo apt autoremove -y
sudo rm -rf /var/lib/postgresql/
sudo rm -rf /etc/postgresql/
# 导入 PostgreSQL 签名密钥
sudo curl -fsSL /media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
# 添加 PostgreSQL 官方仓库
echo "deb [arch=amd64] http://www.landui.com/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
# 更新包列表
sudo apt update
# 安装指定版本的 PostgreSQL
sudo apt install postgresql-16 postgresql-client-16 -y
# 或安装最新版本
sudo apt install postgresql postgresql-client -y
# Ubuntu 22.04 包含 PostgreSQL 14
sudo apt update
sudo apt install postgresql postgresql-contrib -y
# 安装管理工具
sudo apt install pgadmin4 pgadmin4-apache2 -y
# 安装编译依赖
sudo apt install build-essential libreadline-dev zlib1g-dev flex bison \\
libxml2-dev libxslt-dev libssl-dev libsystemd-dev \\
checkinstall python3-dev -y
# 下载源码
cd /tmp
wget /pub/source/v16.1/postgresql-16.1.tar.gz
tar -xzf postgresql-16.1.tar.gz
cd postgresql-16.1
# 配置编译选项
./configure \\
--prefix=/usr/local/pgsql \\
--with-systemd \\
--with-openssl \\
--with-libxml \\
--with-uuid=ossp \\
--with-gssapi \\
--with-ldap \\
--enable-debug \\
--enable-nls \\
CFLAGS='-O2'
# 编译和安装
make -j$(nproc)
sudo make install
sudo make install-world
# 创建系统用户
sudo adduser --system --home /usr/local/pgsql --shell /bin/bash postgres
sudo chown -R postgres:postgres /usr/local/pgsql
# 启动 PostgreSQL 服务
sudo systemctl start postgresql
sudo systemctl enable postgresql
# 检查服务状态
sudo systemctl status postgresql
# 查看版本信息
psql --version
sudo -u postgres psql -c "SELECT version();"
# 查看数据目录
sudo -u postgres psql -c "SHOW data_directory;"
# 查看配置文件位置
sudo -u postgres psql -c "SHOW config_file;"
sudo -u postgres psql -c "SHOW hba_file;"
# 登录到 PostgreSQL
sudo -u postgres psql
# 修改密码
\\password postgres
# 或使用 SQL
ALTER USER postgres WITH PASSWORD 'NewSecurePassword123!';
\\q
# 主配置文件
/etc/postgresql/16/main/postgresql.conf
# 客户端认证配置
/etc/postgresql/16/main/pg_hba.conf
# 初始化配置
/etc/postgresql/16/main/pg_ident.conf
# 数据目录
/var/lib/postgresql/16/main/
# 日志目录
/var/log/postgresql/
8455线路检测中心官网上拥有完善的技术支持库可供参考,大家可自行查阅,更多技术问题,可以直接咨询。同时,8455线路检测中心整理了运维必备的工具包免费分享给大家使用,需要的朋友可以直接咨询。
更多技术知识,8455线路检测中心期待与你一起探索。
售前咨询
售后咨询
备案咨询
二维码

TOP