CentOS7下安装PostgresSQL10

CentOS7下安装PostgreSQL10

1、下载源代码并解压

1. sudo yum install readline-devel gcc gdal-devel libxml-devel proj-devel pcre-devel \
                    bison-devel flex-devel
2. wget https://ftp.postgresql.org/pub/source/v10.6/postgresql-10.6.tar.gz
2. tar -xvzf postgresql-10.6.tar.gz  #解压pg包
3. ./configure
4. sudo make
5. sudo make install

2、创建用户组和用户

1. groupadd postgres    #新增用户组
2. useradd -g postgres postgres    #新增用户
3. passwd postgres    #为用户设置密码

3、创建数据目录

1. mkdir /usr/local/pgsql/data
2. chown postgres /usr/local/pgsql/data    #设置data文件加属性
3. chmod 700 /usr/local/pgsql/data    #设置data文件夹权限

4、数据库操作

1. /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data    #初始化数据库
2. ./pg_ctl start、stop、restart -D /usr/local/pgsql/data/   #启动、停止、重启数据库
3. /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &  #设置日志输出位置
4. /usr/local/pgsql/bin/createdb test    #创建测试数据库
5. /usr/local/pgsql/bin/psql test    #启动测试数据库

5、修改postgresql.conf

1. listen_addresses = '*'
2. port = 5432

6、修改pg_hba.conf

# "local" is for Unix domain socket connections only
local   all             all                                  trust
# IPv4 local connections:
host    all             all             0.0.0.0/0            trust