PostgreSQL 10编译安装(CentOS 7)

摘要:
版本描述:Postgres10.9 CentOS7.6 1安装必要的软件#yumgroup Install-y“开发工具”#yumggroup Install ybisonflexreadline develzlib develgcc 2访问Postgres资源,通过访问https://www.postgresql.org/ftp/source/确定所需版本

  版本说明:      

    Postgres 10.9

    CentOS 7.6

  1 安装必要软件

# yum groupinstall -y "Development tools"
 
# yum install -y bison flex readline-devel zlib-devel gcc

  2 获取Postgres资源并编译安装

  可通过访问https://www.postgresql.org/ftp/source/确定所需版本,以下使用10.9版本进行安装。

# pwd
 
/opt
 
# wget https://ftp.postgresql.org/pub/source/v10.9/postgresql-10.9.tar.gz
 
# tar xf postgresql-10.9.tar.gz
 
# cd postgresql-10.9/
# ./configure --prefix=/opt/pg10/
 
(部分输出内容省略)
 
config.status: creating GNUmakefile
 
config.status: creating src/Makefile.global
 
config.status: creating src/include/pg_config.h
 
config.status: creating src/include/pg_config_ext.h
 
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
 
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
 
config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
 
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
 
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
 
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
 
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
 
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
# make && make install
 
(部分输出内容省略)
 
make[1]: Leaving directory `/opt/postgresql-10.9/src'
make -C config install
make[1]: Entering directory `/opt/postgresql-10.9/config'
/usr/bin/mkdir -p '/opt/pg10/lib/postgresql/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/opt/pg10/lib/postgresql/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/opt/pg10/lib/postgresql/pgxs/config/missing'
make[1]: Leaving directory `/opt/postgresql-10.9/config'
 
PostgreSQL installation complete.
 
 
 
# /opt/pg10/bin/postgres --version
 
postgres (PostgreSQL) 10.9

   3 创建用户

# groupadd -g 2000 postgres
 
# useradd -g 2000 -u 2000 postgres
 
# id postgres
 
# uid=2000(postgres) gid=2000(postgres) groups=2000(postgres)

  4 创建路径及权限修改

# mkdir -p /pgdata/10/{data,backups,scripts,archive_wals}
 
# chown -R postgres:postgres /pgdata/10
 
# chown -R postgres:postgres /opt/pg10
 
# chmod 0700 /pgdata/10/data

  5 环境变量

# su - postgres
 
$ cat .bash_profile
 
# Get the aliases and functions
 
if [ -f ~/.bashrc ]; then
 
. ~/.bashrc
 
fi
 
 
 
# User specific environment and startup programs
 
 
 
export PATH
 
export PGHOME=/opt/pg10
 
export PGDATA=/pgdata/10
 
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
 
 
 
$ source .bash_profile

  6 初始化数据库

$ /opt/pg10/bin/initdb -D /pgdata/10/data/ -W
 
The files belonging to this database system will be owned by user "postgres".
 
This user must also own the server process.
 
 
 
The database cluster will be initialized with locale "en_US.UTF-8".
 
The default database encoding has accordingly been set to "UTF8".
 
The default text search configuration will be set to "english".
 
 
 
Data page checksums are disabled.
 
 
 
Enter new superuser password:
 
Enter it again:
 
 
 
fixing permissions on existing directory /pgdata/10/data ... ok
 
creating subdirectories ... ok
 
selecting default max_connections ... 100
 
selecting default shared_buffers ... 128MB
 
selecting default timezone ... PRC
 
selecting dynamic shared memory implementation ... posix
 
creating configuration files ... ok
 
running bootstrap script ... ok
 
performing post-bootstrap initialization ... ok
 
syncing data to disk ... ok
 
 
 
WARNING: enabling "trust" authentication for local connections
 
You can change this by editing pg_hba.conf or using the option -A, or
 
--auth-local and --auth-host, the next time you run initdb.
 
 
 
Success. You can now start the database server using:
 
 
 
    /opt/pg10/bin/pg_ctl -D /pgdata/10/data/ -l logfile start

  7 启动&关闭

--启动命令
 
$ pg_ctl -D /pgdata/10/data start
 
waiting for server to start....2019-07-19 18:24:02.926 CST [31065] LOG:  listening on IPv6 address "::1", port 5432
 
2019-07-19 18:24:02.926 CST [31065] LOG:  listening on IPv4 address "127.0.0.1", port 5432
 
2019-07-19 18:24:02.929 CST [31065] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
 
2019-07-19 18:24:02.943 CST [31066] LOG:  database system was shut down at 2019-07-19 18:21:30 CST
 
2019-07-19 18:24:02.946 CST [31065] LOG:  database system is ready to accept connections
 
 done
 
server started
 
 
 
--查看后台进程
 
$ ps -ef|grep postgres:
 
postgres  31100  31098  0 18:25 ?        00:00:00 postgres: checkpointer process 
 
postgres  31101  31098  0 18:25 ?        00:00:00 postgres: writer process 
 
postgres  31102  31098  0 18:25 ?        00:00:00 postgres: wal writer process 
 
postgres  31103  31098  0 18:25 ?        00:00:00 postgres: autovacuum launcher process 
 
postgres  31104  31098  0 18:25 ?        00:00:00 postgres: stats collector process 
 
postgres  31105  31098  0 18:25 ?        00:00:00 postgres: bgworker: logical replication launcher
 
postgres  31107  30025  0 18:25 pts/1    00:00:00 grep --color=auto postgres:
 
 
 
--登录验证
 
$ /opt/pg10/bin/pg_isready -p 5432
 
/tmp:5432 - accepting connections
 
 
 
$ psql -p 5432 -U postgres -d postgres
 
psql (10.9)
 
Type "help" for help.
 
 
 
postgres=# q
 
$
--关闭命令
 
$ pg_ctl -D /pgdata/10/data/ -ms stop

  8 修改白名单

  PG默认不允许远程访问数据库,可以通过修改监听地址、修改pg_hba.conf文件来实现远程访问。

--修改监听地址
 
将配置文件中listen_addresses的值由'localhost'修改为'listen_addresses'。
 
$ cp /pgdata/10/data/postgresql.conf /pgdata/10/data/postgresql.conf.bak
 
$ grep listen /pgdata/10/data/postgresql.conf
 
listen_addresses = '*'                # what IP address(es) to listen on;
$ pg_ctl -D /pgdata/10/data/ -ms stop
$ pg_ctl -D /pgdata/10/data start
 
--修改pg_hba.conf文件
 
$ cp /pgdata/10/data/pg_hba.conf /pgdata/10/data/pg_hba.conf.bak
 
$ echo "host postgres postgres 0.0.0.0/0 md5" >> /pgdata/10/data/pg_hba.conf
 
--重新加载配置文件
 
$  /opt/pg10/bin/pg_ctl -D /pgdata/10/data/ reload
 
server signaled


参考资料:

  《PostgreSQL实战》-第一章 
  《PostgreSQL 10.1手册》-III.服务器管理-16.从源码安装
  https://blog.csdn.net/helloworld_dream/article/details/81483235
  https://www.cnblogs.com/tplife2019/p/10234275.html
  http://www.mamicode.com/info-detail-2373348.html

Tank
2019.7.19

https://blog.csdn.net/daiyejava

https://www.cnblogs.com/okey

免责声明:文章转载自《PostgreSQL 10编译安装(CentOS 7)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇吴恩达老师深度学习课程第四周编程作业--一步步搭建多层神经网络以及应用轰炸III下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Postgresql安装

安装postgresql数据的主要两篇参考文档链接: http://www.cnblogs.com/marsprj/archive/2013/02/08/2893519.html http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html 1、下载指定版本的postgresql,这里下载pos...

CentOS 7安装SSHFS 实现远程主机目录 挂载为本地目录

安装sshfs 官方下载地址 https://github.com/libfuse/sshfs/releases 首先,我们需要安装sshfs软件。sshfs是一个基于SSH文件传输协议的文件系统客户端,它的官方网页是:http://fuse.sourceforge.net/sshfs.html 。在CentOS下,我们可以通过yum来安装(注意使用yum...

webpack使用的心得

1 . 我们需要使用打包工具,首先第一步就得 执行 npm install进行安装,可是很多时候 加载速度很慢,这个时候我们可以 用淘宝镜像源,参考地址: https://npm.taobao.org/ 使用方法如下: npm install --registry=https://registry.npm.taobao.org 全局配置镜像源: 淘宝镜像:...

Centos 7 搭建蓝鲸V4.1.16社区版

第一次搭建蓝鲸平台,参考了蓝鲸社区的官方搭建文档。 友情链接:蓝鲸智云社区版V4.1.16用户手册 在本地用VMware模拟了三台主机, 准备至少3台 CentOS 7 以上操作系统的机器 最低配置:2核4G 建议配置: 4核12G 以上 192.168.1.12(主控机) 192.168.1.18 192.168.1.19 获取安装包 蓝鲸社区版包含...

经纬度WGS84地理坐标系转换成CGCS2000坐标系步骤,必备!

经纬度WGS84地理坐标系转换成CGCS2000坐标系步骤 基于ArcGIS中进行操作 1、 将图层从奥维中导出成shp文件, 2、 打开arcgis-arcmap 3、地理处理-arctoolbox-数据管理工具-投影和变换-要素-投影 ![](data:image/svg+xml;utf8,) 4、WGS84坐标转换为地理坐标系-world-IT...

VMware Data Recovery备份恢复vmware虚拟机

VMware Data Recovery 是VMware虚拟机备份工具,可创建虚拟机备份,同时不会中断虚拟机的使用或虚拟机提供的数据和服务。Data Recovery 管理现有备份,并在这些备份过时后将其删除。它还支持删除重复以删除冗余数据。 1.1 系统需求 在安装 VMware Data Recovery 之前,请确保环境中的系统和存储可用。 VMwa...