系统版本 Centos7.6
工具:xshell6
PostgreSql: postgresql-11.2.tar.gz
官网下载PostgreSQL 11.2源码地址:https://www.postgresql.org/ftp/source/v11.2/
选择postgresql-11.2.tar.gz
tar -zxvf postgresql-11.2.tar.gz
cd postgresql-11.2
./configure --prefix=/usr/local/postgresql --without-readline
make && make install
cd /usr/local/postgresql/
yum -y install postgresql11
mkdir /usr/local/postgresql/data
mkdir /usr/local/postgresql/log
chmod -R 775 /usr/local/postgresql/data
vim /etc/profile
PGHOME=/usr/local/postgresql
export PGHOME
PGDATA=/usr/local/postgresql/data
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH
使配置文件生效
source /etc/profile
useradd postgres
将pg的数据目录全部赋给postgres用户,执行以下命令:
chown -R postgres:postgres /usr/local/postgresql/
切换到postgres用户,执行如下命令:
su - postgres
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/
/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile start
查看数据库版本
psql -V
psql (PostgreSQL) 11.2
psql -U postgres -d postgres
目录/usr/local/postgresql/data/下,pg_hba.conf和postgresql.conf两个文件。
vi /usr/local/postgresql/data/pg_hba.conf
vi /usr/local/postgresql/data/postgresql.conf
修改listen_addresses = ‘*’;
psql -U postgres -d postgres
firewall-cmd --zone=public --add-port=8432/tcp --permanent
firewall-cmd --reload
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl restart postgresql-11
自动启动
systemctl enable postgresql-11.service
启动
systemctl start postgresql-11.service
停止某服务
systemctl stop postgresql-11.service
不自动启动
systemctl disable postgresql-11.service
检查服务状态(服务详细信息)
systemctl status postgresql-11.service
检查服务状态(仅显示是否Active)
systemctl is-active postgresql-11.service
显示所有已启动的服务
systemctl list-units --type=service
参考
https://yq.aliyun.com/articles/715609
https://blog.csdn.net/llwy1428/article/details/95444151