linux下安装postgresql 9.4数据库

【摘要】 linux下安装postgresql 9.4数据库

#安装相关依赖包
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++   openssl-devel cmake

#切换到src/目录下
cd /usr/local/src/
yum -y install wget
wget https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.gz
#解压
tar xf postgresql-9.4.1.tar.gz
#切换到postgresql-9.4.1
cd postgresql-9.4.1
#编译安装 PostgreSQL
./configure --prefix=/usr/local/pgsql --with-perl --with-python --with-libxml --with-libxslt
make && sudo make install
gamke
gamke install

cd /usr/local/src/postgresql-9.4.1/contrib
gmake
gmake install

#添加动态库
echo "/usr/local/pgsql/lib" >> /etc/ld.so.conf.d/pgsql.conf
ldconfig
#创建用户postgres
useradd postgres
mkdir -p /data/pg/data
#授权
 chown -R postgres:postgres /data/pg
#切换到postgres用户
su postgres
/usr/local/pgsql/bin/initdb --no-locale -U postgres -E utf8 -D /data/pg/data -W
#回到root用户,配置运行环境变量
su
vi /etc/profile
添加如下代码
PGDATA=/data/pg/data
PGHOST=127.0.0.1
PGDATABASE=postgres
PGUSER=postgres
PGPORT=5432
PATH=/usr/local/pgsql/bin:$PATH
export PATH
export PGDATA PGHOST PGDATABASE PGUSER PGPORT

#立即生效
source /etc/profile

#切换postgres用户
su postgres
pg_ctl start -D /data/pg/data
cp /usr/local/src/postgresql-9.4.1/contrib/start-scripts/linux /etc/init.d/postgresql
chmod +x /etc/init.d/postgresql
psql -h 127.0.0.1 -U postgres -p 5432 -d postgres -W

#查找pg_hba.conf和postgresql.conf
find / -name pg_hba.conf

find / -name postgresql.conf

#添加如下内容  表示所有地址都可以访问
vi /data/pg/data/pg_hba.conf
host    all             all             0.0.0.0/0          md5

#修改配置使能远程访问
 vi /data/pg/data/postgresql.conf

#将注释去掉,修改如下图

#su postgres pg_ctl restart -D /usr/local/pgsql/

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享