PostgreSQL-10.1 linux安装配置

卸载旧版本
rpm -qa | grep postgres    检查PostgreSQL 是否已经安装
rpm -qal | grep postgres   检查PostgreSQL 安装位置
rpm -e 卸载


下载地址:
http://www.postgresql.org/download/linux/redhat/    


解压
tar -zxvf postgresql-10.1.tar.gz


编译安装
./configure --prefix=/opt/pgsql-10.1
make
make install


查看安装目录
ls /opt/pgsql-10.1


创建用户并且切换用户postgres
useradd postgres
passwd postgres
su postgres


设置环境变量
vim ~/.bash_profile
添加以下变量
export PGHOME=/opt/pgsql-10.1
export PGDATA=~/data
保存退出,生效环境变量
source ~/.bash_profile


初始化数据库
initdb
启动数据库实例
pg_ctl start
查看运行的postgres进程
ps -ef | grep postgres
连接postgresql数据库
psql -h 127.0.0.1 -d postgres -U postgres
停止postgresql数据库实例
pg_ctl stop
查看运行的postgres进程
ps -ef |  grep postgres


给linux文件添加X(执行)属性
cd /work/postgresql-10.1/contrib/start-scripts/
chmod a+x linux
复制linux文件到/etc/init.d目录下,更名为postgresql
cp linux /etc/init.d/postgresql
修改/etc/init.d/postgresql文件的两个变量
vim /etc/init.d/postgresql
prefix=/opt/pgsql-10.1
PGDATA=/work/postgresql-10.1/data/
启动PostgreSQL服务
service postgresql start
设置postgresql服务开机自启动
chkconfig --add postgresql

猜你喜欢

转载自blog.csdn.net/vitaair/article/details/80195860