step1:官网下载postgres源码
URL:https://www.postgresql.org/ftp/source/
step2:解压源码文件
tar -zxvf postgresql-12.0.tar.gz
step3:移动解压后的文件到安装目录
mvpostgresql-12.0 /usr/local/pgsql
./configure --prefix=/usr/local/pgsql --without-readline --enable-debug
指定安装后的可执行文件资源目录
make
make install
psql --version //查询安装版本
切换用户 su - postgres 打开文件 vim ~/ .bash_profile 添加路径 export PATH=$PATH:/usr/local/pgsql/bin 执行生效 source/etc/profile
sudo adduser postgres sudo passwd postgres sudo mkdir -p /usr/local/pgsql/data sudo chown -R postgres:root /usr/local/pgsql
su - postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
cp /usr/local/pgsql/contrib/start-scripts/linux /etc/init.d/postgresql //将linux文件复制到新目录init.d,并重命名为postgresql
chmod u+x /etc/init.d/postgresql //只授予这个文件的所属者u执行的权限x
systemctl enable postgresql
systemctl start postgresql
step11:创建测试库(切换到用户postgres下执行命令)
su - postgres
createdb test
psql test
step12:允许所有连接
打开文件 /usr/local/pgsql/data/pg_hba.conf 添加内容 host all all 0.0.0.0/0 trust
step13:侦听所有连接
打开文件 /usr/local/pgsql/data/postgresql.conf 添加内容 listen_addresses = ‘*‘ logging_collector = on
原文:https://www.cnblogs.com/mobaiyu/p/11753241.html