postgresql-13安装及数据目录切换

摘自官网:https://www.postgresql.org/download/linux/redhat/

 使用root账号,不需要使用sudo

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql13-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
数据目录在 /dev/mapper/centos-root 目录下, 生产需要注意变更数据目录
数据目录更换:
停止pg: systemctl stop postgresql-13
创建更换目录: mkdir -p /home/pgsql/13
迁移原数据到新目录: cp -rf /var/lib/pgsql/13/data /home/pgsql/13/
目录权限变更: chown -R postgres:postgres /home/pgsql/        chmod -R 750 /home/pgsql
修改配置文件: vi /usr/pgsql-13/bin/postgresql-13-setup 中 PREVDATADIR=/home/pgsql/$PREVMAJORVERSION/data 修改启动文件: vi /usr/lib/systemd/system/postgresql-13.service 中 Environment=PGDATA=/home/pgsql/13/data/ 启动:systemctl start postgresql-13
参考链接:
https://blog.csdn.net/u011250186/article/details/103770562
posted on 2021-08-15 19:36  yangshanbo2010  阅读(703)  评论(2编辑  收藏  举报