PostgreSQL 12 源码安装

1 下载

官网提供了源码和预安装的版本。 源码需要编译安装,解决依赖包等问题,而预安装的版本要简单很多。只需下载解压, 初始化数据库即可。

本例以源码安装为例:请至官网 下载源码。

本例中安装的是PG12. 在 https://www.postgresql.org/ftp/source/v12.0/ 中选择postgresql-12.0.tar.bz2

请根据需要先择自己需要的版本。

预安装版本,请至官网下载。

2 准备环境

此步骤以root用户执行。 将postgresql的安装包放到/opt 路径。

# 创建组和用户
groupadd postgre
useradd -g postgre -G postgre -d /home/postgresql postgre
passwd postgre
# 安装依赖包
yum install -y bzip2 readline-devel zlib-devel
# 将安装包放在/opt 路径中并解压
cd /opt/
bunzip2 postgresql-12.0.tar.bz2
tar -xvf ./postgresql-12.0.tar

3 编译安装

此步骤以postgre 用户操作:

cd /opt/postgresql-12.0
./configure --prefix=/home/postgresql/dbhome
make && make install

安装后,可执行文件,库文件等都会安装在/home/postgresql/dbhome 中。

[postgre@boss20 dbhome]$ ls /home/postgresql/dbhome
bin include lib share

4 设置环境变量

将以下两行添加至postgre 用户的环境变量文件 .bash_profile 并生效。

export LD_LBRARY_PATH=$HOME/dbhome/lib:$LD_LIBRARY_PATH
export PATH=$HOME/dbhome/bin:$PATH

环境变量文件生效方法:

. .bash_profile
或者
source .bash_profile

5 初始化数据库

此步骤以postgre用户执行。

  • 创建数据存放路径

    mkdir $HOME/data
    

    postgresql 数据库的配置文件,数据文件等都会存放在这个路径下。

  • 初始化数据库

    initdb --locale=C -E UNICODE -D $HOME/data/
    

    示例如下:

      The files belonging to this database system will be owned by user "postgre".
    This user must also own the server process. The database cluster will be initialized with locale "C".
    The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /home/postgresql/data ... ok
    creating subdirectories ... ok
    selecting dynamic shared memory implementation ... posix
    selecting default max_connections ... 100
    selecting default shared_buffers ... 128MB
    selecting default time zone ... America/New_York
    creating configuration files ... ok
    running bootstrap script ... ok
    performing post-bootstrap initialization ... ok
    syncing data to disk ... ok initdb: 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: pg_ctl -D /home/postgresql/data/ -l logfile start

初始化完成后,在最后一行会提示我们启动数据库的方法. 此时我们来查看一下 $HOME/data路径 的内容:

[postgre@boss20 data]$ ls
base pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_wal postgresql.auto.conf
global pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VERSION pg_xact postgresql.conf

这些路径分别有什么用途,以后再了解。

6 配置参数文件

我们主要是配置postgresql.conf 和 pg_hba.conf 这两个。

  • postgresql.conf 针对实例的配置
  • pg_hba.conf 针对数据库访问的控制

6.1 postgresql.conf

找到 #port#listener_address 这两个参数。这两个参数是相邻的:

#listen_addresses = 'localhost'               # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)

将两行行首的 # 删除,将 localhost 改为当前服务器的IP 。 默认的监听端口是5432,可以自行指定另外一个端口号,*不抢建使用默认端口号* 。 顺便再修改一下 max_connections 吧,最大的连接数, 100有点少,特别是业务系统。 可以调整成1000,或者更高。

6.2 pg_hba.conf

将以下一行添加至文末。

host    all             all             10.10.100.0/24          trust

其意义是允许 10.10.100网段的IP 连接此服务器上的PG. 如果想允许所有IP 都可以连接此服务器 则可以配置成如下:

host    all             all             0.0.0.0/0          trust

7 数据库启动与关闭

 

7.1 手动

我们手动启动与关闭数据库是执行pg_ctl命令。在执行时,需要指定 数据路径,格式如下:

pg_ctl -D <数据存放路径> [ stop | start ]

示例如下:

[postgre@boss20 data]$ pg_ctl -D /home/postgresql/data/ -l logfile start
waiting for server to start.... done
server started
[postgre@boss20 data]$ pg_ctl -D $HOME/data stop
waiting for server to shut down.... done
server stopped

7.2 开机自动启动

此步骤需要root用户操作。 postgresql 的安装包中提供了数据库启动与关闭的脚本,可以帮助我们简化操作,也可以 用作开机启动的脚本和service/systemctl 控制服务的脚本。 脚本位于:

<path>/postgresql-12.0/contrib/start-scripts/
本示例中是:
/opt/postgresql-12.0/contrib/start-scripts/

设置开机启动:

cp /opt/postgresql-12.0/contrib/start-scripts/linux /etc/init.d/postgresql
chkconfig --add postgresql
chmod 755 /etc/init.d/postgresql

调整配置,主要是脚本中三个变量的值:

prefix="/home/postgresql/dbhome"
PGDATA="/home/postgresql/data"
PGUSER=postgre
  • prefix 是软件的安装路径
  • PGDATA 是数据存放路径
  • PGUSER 是启动postgresql服务的用户

以后可以开机启动和通过service 命令控制启动和关闭了:

[root@boss20 init.d]# service postgresql start
Starting PostgreSQL: ok
[root@boss20 init.d]# service postgresql stop
Stopping PostgreSQL: ok

Author: halberd.lee

Created: 2019-10-18 Fri 18:05

Validate

CentOS7 源码安装 PostgreSQL 12的更多相关文章

  1. Centos7 源码安装PostgreSQL Citus集群 (转载)

    citus的分布式集群目前在苏宁大规模应用,苏宁陈华军也做了很多技术分享和博客介绍.目前所有的教程都是rpm和pg一起安装,个人不喜欢,毕竟citus定位是个插件,我想在我已安装的pg上源码装一个ci ...

  2. centos7源码安装Python3的前提条件

    centos7源码安装Python3的前提条件: # yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline- ...

  3. centos7源码安装mysql5.7.19

    centos7源码包安装mysql5.7 5.7.20安装方法和5.7.19的一样. 1.安装前准备 清空环境.安装相应的软件包 1>关闭防火墙和SELinux 2>配置yum源(阿里云, ...

  4. CentOS7源码安装qbittorrent最新版本

    CentOS的软件 yum 里 yum search qbittorrent yum info qbittorrent 找到的是3.37版本 官网最新的是4.12版本.但需要源码安装: 官网下载最新版 ...

  5. CentOS7源码安装Redis5.0.4非关系型数据库

    源码安装redis-5.0.4 一. 下载redis 1. 需要连接网络 二. 案例(另一种安装方法) [root@localhost ~]# wget http://download.redis.i ...

  6. 国产龙芯服务器源码安装PostgreSQL数据库的方法

    1. 公司最近有一些国产化项目的需求, 要求在国产CPU的服务器上面安装pg数据库等. 2.. 但是差查了下中标麒麟的官网,在龙芯MIPS的操作系统包源里面仅有 postgreSQL 9.2 版本的r ...

  7. Centos7源码安装Apache和PHP

    源码安装Apache 安装需要的依赖 yum -y install gcc autoconf automake make pcre pcre-devel openssl openssl-devel​# ...

  8. Centos7源码安装mysql及读写分离,互为主从

       Linux服务器 -源码安装mysql 及读写分离,互为主从   一.环境介绍: Linux版本: CentOS 7 64位 mysq版本: mysql-5.6.26 这是我安装时所使用的版本, ...

  9. centos7源码安装Apache及Tomcat

    源码安装Apache (1) 一.通过 https://apr.apache.org/  下载 APR 和 APR-util 通过 http://httpd.apache.org/download.c ...

随机推荐

  1. (备忘)Linux mount(挂载命令)详解

    挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的. 命令格式:mount [-t vfstype] [-o option ...

  2. 《数据结构与算法之美》 <02>复杂度分析(下):浅析最好、最坏、平均、均摊时间复杂度?

    上一节,我们讲了复杂度的大 O 表示法和几个分析技巧,还举了一些常见复杂度分析的例子,比如 O(1).O(logn).O(n).O(nlogn) 复杂度分析.掌握了这些内容,对于复杂度分析这个知识点, ...

  3. python基础:数据类型一

    一.可变不可变类型 二.数字类型 三.字符串类型 四.列表类型 一.可变不可变类型 #可变类型: 值变了,但是id没有变,证明没有生成新的值而是在改变原值,原值是可变类型 #不可变类型:值变了,id也 ...

  4. JSON添加注释的问题

    JSON有两种数据结构: 名称/值对的集合:key : value样式: 值的有序列表:就是Array: 而在JSON的文档中说明只要是不符合上面两种结构的都不被支持,并提示错误 添加注释//或者/* ...

  5. Lambda使用深入解析

    这一次继续对Lambda表达式进行深入,因为它实在太重要了,这次会涉及到java.util.function中的一些新的FunctionalInterface的使用,用它来进一步巩固对Lambda表达 ...

  6. 【Java 关键字this 的使用】还阔以调用重载的构造方法

    笔记: /** this 关键字的使用除了调用方法和变量外, * 还可以用来显示 调用当前类的重载的指定的构造方法! * 同时也应该必须放到该方法内部的首行! */ 测试: import java.l ...

  7. systemctl可以实现nginx进程挂了之后自动重新启动

    接 2018年7月31日的那篇: vim /lib/systemd/system/nginx.service [Service]Restart=alwaysRestartSec=1Type=forki ...

  8. win10快速设置环境变量

    同时按WIN+R键,打开“运行”对话框,输入sysdm.cpl,按回车键打开“系统属性”. 在系统属性对话框中选择“高级”选项卡.

  9. C# 异步编程 (12)

    异步编程重要性 C# 5.0 提供了更强大的异步编程.添加两个新的关键字 async 和 await . 使用异步编程,方法调用是在后台运行(通常在线程或任务的帮助下),并且不会阻塞调用线程. 3种不 ...

  10. [唐胡璐]Selenium技巧- 抓图并保存到TestNG报告中

    这里不讲解怎么在Eclipse安装配置TestNG,网上一搜一大把,大家自己去实践一下。 在这里主要说一下用Java来实现Selenium Webdriver的截图功能和把截图写到TestNG的报告中 ...