linux下安装postgresql(Wget方式)

环境:linux

数据库:postgresql 9.4.1

我是用root用户登录的服务器.我的路径在/opt/postgresql

1.软件下载

//切换到/opt/postgresql目录下
cd /opt/postgresql
//使用命令下载postgresql
wget https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.gz

2.安装依赖包

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

3.安装postgresql

//进行解压
tar xf postgresql-9.4.1.tar.gz

//解压完,依次输入该命令
./configure --prefix=/opt/postgresql/pgsql --with-perl --with-python --with-libxml --with-libxslt

gmake

gmake install

4.安装PG插件

cd /opt/postgresql/src/postgresql-9.4.1/contrib
gmake
gmake install

5.加载动态库

echo "/opt/postgresql/pgsql/lib" >> /etc/ld.so.conf.d/pgsql.conf
ldconfig

6.初始化数据库

创建用户

useradd postgres
echo "postgres"|passwd --stdin postgres

7.创建PG数据目录

mkdir -p /data/pg/data
chown -R postgres:postgres /data/pg
/opt/postgresql/pgsql/bin/initdb --no-locale -U postgres -E utf8 -D /data/pg/data -W

注:(在初始化的时候,注意看提示 设置 超级用户的密码).

8.配置运行环境变量(方便管理)

vim /etc/profile

在最后一行添加以下代码:

export PGDATA=/data/pg/data
export PATH=/opt/postgresql/pgsql/bin:$PATH

9.执行命令,使配置文件生效

source /etc/profile

10.postgresql服务管理

启动:

pg_ctl start -D /data/pg/data

猜你喜欢

转载自blog.csdn.net/mqingo/article/details/83781975