官网下载源码包
https://www.postgresql.org/ftp/source/v12.10/
postgresql-12.10.tar.gz 上传到/usr/local目录
tar -zxvf postgresql-12.10.tar.gz 解压文件
cd postgresql-12.10
依次执行如下命令
./configure
make
sudo make install
如果执行中报如下错误
则需要安装readline的依赖(可以通过阿里巴巴的rpm下载)
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
readline-6.2-11.el7.x86_64.rpm
readline-devel-6.2-11.el7.x86_64.rpm
上传到/usr/local/readline目录
然后进入/usr/local/readline执行命令
rpm -Uvh *.rpm --nodeps --force
sudo groupadd postgres
sudo useradd -g postgres postgres
sudo passwd postgres
这里创建账号 postgres/postgres
sudo mkdir -p /usr/local/pgsql/data
sudo chown -R postgres:postgres /usr/local/pgsql/data
sudo chown postgres:postgres /var/log
sudo -u postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
sudo vi /etc/systemd/system/postgresql-12.service
[Unit] Description=PostgreSQL 12 database server Documentation=https://www.postgresql.org/docs/12/static/ After=network.target [Service] Type=forking User=postgres ExecStart=/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l /var/log/postgresql.log ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data -l /var/log/postgresql.log ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D /usr/local/pgsql/data # Give a reasonable amount of time for the server to start up/shut down TimeoutSec=300 [Install] WantedBy=default.target
sudo systemctl daemon-reload
sudo systemctl start postgresql-12.service
sudo systemctl enable postgresql-12.service
开启远程访问
修改文件 /usr/local/pgsql/data/postgresql.conf
/usr/local/pgsql/data/pg_hba.conf
然后执行如下命令重启postgres
sudo systemctl stop postgresql-12.service
sudo systemctl start postgresql-12.service
使用navicat连接上数据库后,执行如下命令修改账号postgres的密码
ALTER USER postgres WITH PASSWORD 'postgres';
然后将pg_hba.conf文件里面的
host all all 0.0.0.0/0 trust
改成
host all all 0.0.0.0/0 md5
然后重启postgres服务
其他说明
登录postgres
sudo -u postgres /usr/local/pgsql/bin/psql
然后可以直接输入命令修改postgres账号的密码
\q 退出postgres
卸载安装的postgres
先停止数据库
sudo rm /etc/systemd/system/postgresql-12.service
sudo systemctl daemon-reload
删除安装目录:
sudo rm -rf /usr/local/postgresql-12.10
删除数据目录:
sudo rm -rf /usr/local/pgsql
删除用户和用户组
sudo userdel -r postgres
sudo groupdel postgres
标签:pgsql,postgresql,postgres,sudo,离线,centos7,usr,local From: https://www.cnblogs.com/james-roger/p/17637407.html