PG | PostgreSQL 10编译安装(CentOS 7)

news/2024/7/9 23:23:10 标签: PostgreSQL

版本说明:

        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


http://www.niftyadmin.cn/n/1146676.html

相关文章

Doevents函数详解

Doevents函数是一个很好用的函数,但很多人对它的用法不清楚或有误解。由于我在网上查到一篇关于此函数的用法,并添加了一些内容,不敢独享,特此献出。其中有一个“控时循环和变速齿轮”的内容,有点意思,感兴…

PG | psql元命令使用说明

版本说明: PostgresQL 10.9 psql提供了丰富的元命令,以“\”开头,使用元命令可以高效、便捷的对数据库进行管理。psql命令的格式是用反斜线后面直接跟上一个命令动词,然后是一些参数。 在使用前可以使用“\?”来获取帮助信息&am…

NumPy实现逻辑回归

说明:数据集 ex2data1.txt是吴恩达机器学习的作业的数据集。 # -*-coding:utf-8-*- import matplotlib.pyplot as plt import numpy as np import pandas as pdclass Logitstic_Regression:def __init__(self, learning_rate0.01, num_iterations75000, threshold0.…

【ASP.NET】Aspnetpager对GridView分页,并导出Excel

一、前言 谈到分页,在网页上简直到处都是。网络的资源越来越多,如果不用分页技术来显示,就会拖拉很长很长。下面给大家分享分页技术。 二、基本要点 当要显示数据量足够大的时候,我们往往采用分页显示的处理办法。分页有真分页和…

老路《用得上的商学课》学习开篇(自序)

图片来自《用得上的商学课》课程封面这套音频课程是朋友在2018年初推荐给我的,时隔一年半,依旧能记得朋友当初被老路吸粉的样子,最近他已经开始了老路第二季课程,惭愧的我下决心把囤的这套课程学习一遍,每天将学习心得…

前谷歌员工推Cuil 获3300万风投对战老东家

7月30日消息,据国外媒体报道,日前,前谷歌公司技术开发人员安娜帕特森 (Anna Patterson)推出了一种新命名为Cuil的搜索引擎,决心挑战谷歌。据国外媒体报道,帕特森于2006年从谷歌辞职,并决心要开发出能够更高…

Oracle | ORA-03135: connection lost contact.

版本说明:Oracle 12.1.0.2 问题描述: 某B/S架构的应用程序在测试过程中每隔1到2小时出现“错误信息:ORA-03135: 连接失去联系的报错”,详细报错信息如下: 类名及方法:XXXX.XXT.Filter.ExtendedHandleError…

杨元庆:出身中国是联想吸引国际用户的障碍

8月1日消息,据国外媒体报道,联想董事长杨元庆周四表示,出身中国是联想吸引国际用户的最大障碍。因此,与其他公司相比,联想吸引用户的成本更高。杨元庆说:“最大障碍是我们来自中国,一个新兴市场…