源码安装PostgreSQL

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB PostgreSQL 版,企业版 4核16GB
推荐场景:
HTAP混合负载
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
简介: 数据库版本:PostgreSQL 9.6.3系统版本:CentOS release 6.6 (Final)下载软件(Download software):[root@Darren2 tools]# wget https://ftp.

数据库版本:

PostgreSQL 9.6.3


系统版本:

CentOS release 6.6 (Final)


下载软件(Download software):

[root@Darren2 tools]# wget https://ftp.postgresql.org/pub/source/v9.6.3/postgresql-9.6.3.tar.gz


查看是否已经安装(Check is not instatll):

[root@Darren2 tools]# ps -ef |grep pgsql

root      28590  18695  0 20:24 pts/0    00:00:00 grep pgsql

[postgres@sht-sgmhadoopdn-02 ~]$ rpm -qa |grep postgres

postgresql-libs-8.4.18-1.el6_4.x86_64


解压(Extract software):

[root@Darren2 tools]# tar xf postgresql-9.6.3.tar.gz


编译和安装(Complie):

[root@Darren2 tools]# cd postgresql-9.6.3

[root@Darren2 postgresql-9.6.3]# ./configure --prefix=/usr/local/pgsql

 

编译所有能编译的东西,包括文档(HTML和手册页)以及附加模块(contrib):

[root@Darren2 postgresql-9.6.3]# make world && make install-world

......

make[2]: Leaving directory `/home/tools/postgresql-9.6.3/contrib/vacuumlo'

make[1]: Leaving directory `/home/tools/postgresql-9.6.3/contrib'

PostgreSQL, contrib, and documentation installation complete.


创建用组和用户(Create group and user)

[root@Darren2 ~]# groupadd -g 101 dba

[root@Darren2 ~]# cat /etc/group|grep dba

dba:x:101:

[root@Darren2 ~]# useradd -u 516 -g dba -G root -d /usr/local/pgsql  postgres

[root@Darren2 ~]# id postgres

uid=516(postgres) gid=101(dba) groups=101(dba),0(root)

-u UID

-g 初始用户组

-G次要用户组

-m 创建用户家目录(系统用户默认不创建家目录)

-M 不创建用户家目录(普通用户默认创建家目录)

-s shell 默认是/bin/bash

-d指定家目录


[root@Darren2 home]# groups postgres

postgres : dba root


配置postgres密码

[root@Darren2 home]# passwd postgres


[root@Darren2 skel]# ls -al /etc/skel/

total 20

drwxr-xr-x.  2 root root 4096 Dec 20  2016 .

drwxr-xr-x. 84 root root 4096 Jul 11 22:27 ..

-rw-r--r--.  1 root root   18 Jul 18  2013 .bash_logout

-rw-r--r--.  1 root root  176 Jul 18  2013 .bash_profile

-rw-r--r--.  1 root root  124 Jul 18  2013 .bashrc

[root@Darren2 skel]# cp /etc/skel/.* /usr/local/pgsql/


创建数据目录(Create data folder)

[root@Darren2 ~]# mkdir -p /usr/local/pgsql/data


配置.bash_profile(Configure .bash_profile)

[root@Darren2 pgsql]# cat /usr/local/pgsql/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

    . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PGHOME=/usr/local/pgsql

export PGDATA=/usr/local/pgsql/data

export PATH=$PATH:/usr/local/pgsql/bin

set umask to 022

umask 022

PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1


修改文件权限和所有者(Chmod and chown)

[root@Darren2 pgsql]# chmod -R 755 /usr/local/pgsql

[root@Darren2 pgsql]# chown -R postgres:dba /usr/local/pgsql

[root@Darren2 pgsql]# chmod -R 700 /usr/local/pgsql/data


配置postgresql服务启动和设置自启动(Configure postgresql service and boot auto start) --这步可不做

[root@Darren2 start-scripts]# cp /home/tools/postgresql-9.6.3/contrib/start-scripts/linux /etc/init.d/postgresql

[root@Darren2 start-scripts]# chmod +x /etc/init.d/postgresql

[root@Darren2 start-scripts]# chkconfig --list |grep postgresql

[root@Darren2 start-scripts]# chkconfig --add postgresql

[root@Darren2 start-scripts]# chkconfig --list |grep postgresql

postgresql         0:off    1:off    2:on    3:on    4:on    5:on    6:off


初始化数据和启动(Initialize database and start database)

[root@Darren2 start-scripts]# su - postgres

[postgres@Darren2 start-scripts]$ cd

[postgres@Darren2 ~]$ pwd

/usr/local/pgsql

[postgres@Darren2 ~]$ . .bash_profile


#初始化生成数据文件

Darren2:postgres:/usr/local/pgsql:>/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data


#启动数据库

Darren2:postgres:/usr/local/pgsql:>pg_ctl start

server starting

Darren2:postgres:/usr/local/pgsql:>LOG:  database system was shut down at 2017-07-12 00:49:17 CST

LOG:  MultiXact member wraparound protections are now enabled

LOG:  database system is ready to accept connections

LOG:  autovacuum launcher started


创建用户和数据库(Create user and database)

psql

psql (9.6.3)

Type "help" for help.

postgres=# create user admin password'admin' login;

CREATE ROLE

postgres=# create database testdb with owner=admin;

CREATE DATABASE


Darren2:postgres:/usr/local/pgsql:>pg_ctl status

pg_ctl: server is running (PID: 51498)

/usr/local/pgsql/bin/postgres


安装过程中常见报错

编译时候报错:

[root@Darren2 postgresql-9.6.3]# ./configure --prefix=/usr/local/pgsql --without-zlib

......

configure: error: readline library not found  --提示找不到readline

If you have readline already installed, see config.log for details on the

failure.  It is possible the compiler isn't looking in the proper directory.

Use --without-readline to disable readline support.

查看系统已经安装readline:

[root@Darren2 postgresql-9.6.3]# rpm -qa |grep readline

compat-readline5-5.2-17.1.el6.x86_64

readline-6.0-4.el6.x86_64

通过yum search可以发现没有安装readline-devel:

[root@Darren2 postgresql-9.6.3]# yum search readline

......

readline-devel.i686 : Files needed to develop programs which use the readline library

readline-devel.x86_64 : Files needed to develop programs which use the readline library

......

通过yum安装之后,在编译即可通过:

[root@Darren2 postgresql-9.6.3]# yum install -y readline-devel

    

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
2月前
|
SQL 缓存 关系型数据库
postgresql的安装和使用
postgresql的安装和使用
64 0
|
2月前
|
关系型数据库 PostgreSQL
postgresql安装
postgresql安装
58 8
|
2月前
|
SQL 关系型数据库 数据库
如何在 Debian 12 上安装 PostgreSQL?
【4月更文挑战第25天】
123 0
|
10月前
|
SQL 关系型数据库 编译器
PostgreSQL 16源码安装
PostgreSQL 16源码编译,涵盖gcc、clang、pg jit
355 0
|
存储 网络协议 安全
tlinux 3.1 安装 postgresql 13.x
TencentOS Server 3.1 安装 PostgreSQL 13.x
231 0
tlinux 3.1 安装 postgresql 13.x
|
关系型数据库 开发工具 PostgreSQL
|
存储 Ubuntu 关系型数据库
PostgreSQL安装和使用
[TOC] ### postgresql安装 window - - - [一、安装](https://edu.csdn.net/skill/pg/pg-940afa6d71af44f689011ded8fd91a98?category=594&typeId=20367#_2) - [二、初始化配置](https://edu.csdn.net/skill/pg/pg-940afa6d71af44f689011ded8fd91a98?category=594&typeId=20367#_27) - [三、启动](https://edu.csdn.net/skill/pg/p
396 0
|
关系型数据库 Linux 数据库
|
关系型数据库 数据库 数据安全/隐私保护
PostgreSQL windows安装
windows安装注意
170 0
|
关系型数据库 数据库 开发工具
PostgreSQL 10.0 源码安装
源码安装 tar zxvf postgresql-10.0.tar.gz mv postgresql-10.0 /usr/local/pgsql cd /usr/local/pgsql/ root用户下安装依赖包 yum -y install gcc gcc-c++ automake auto...
1691 0