postgresql编译安装及配置

1、建立postgres用户

[[email protected] source]# adduser postgres

2、下载postgresql源码

[[email protected] source]# pwd

/home/postgres/source

[[email protected] source]# wget https://ftp.postgresql.org/pub/source/v9.6.1/postgresql-9.6.1.tar.gz

3、编译安装postgresql:

[[email protected] source]# pwd

/home/postgres/source

[[email protected] source]# tar zxf postgresql-9.6.1.tar.gz

[[email protected] source]# cd postgresql-9.6.1

[[email protected] postgresql-9.6.1]# ./configure --prefix=/usr/local/pgsql9.6.1

[[email protected] postgresql-9.6.1]# gmake -j 8

[[email protected] postgresql-9.6.1]# gmake install

4.初始化数据库:

mkdir -p /data/postgresql5.6/data

chown -R postgres.postgres /data/postgresql5.6/data

[[email protected] postgresql-9.6.1]# su - postgres

[[email protected] data]$

/usr/local/pgsql9.6/bin/initdb --no-locale  -D /data/postgresql5.6/data -E utf8 -U postgres -W

[[email protected] data]$  /usr/local/pgsql9.6/bin/initdb --no-locale  -D /data/postgresql5.6/data -E utf8 -U postgres -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 "C".

The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password: (要求输入超级用户postgres密码)

Enter it again:

fixing permissions on existing directory /data/postgresql5.6/data ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

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:

/usr/local/pgsql9.6/bin/pg_ctl -D /data/postgresql5.6/data -l logfile start

/usr/local/pgsql9.6/bin/initdb --no-locale  -D /data/postgresql5.6/data -E utf8 -U postgres -W

5.初始化数据库的参数介绍:

initdb [OPTION] [DATADIR]

选项:

-A,--auth=METHOD:指定本地连接的认证方法

[-D,--pgdata=]DATADIR:指定数据库簇的原始目录(必须为空)

-E,--encoding=ENCODING:指定数据库的默认编码

--locale=LOCALE:设置数据库的locale

--no-locale:等价--locale=C

--pwfile=FILE:从指定的文件FILE中读取超级用户的密码

-T,--text-search-config=CFG:指定默认的配置

-U,--username=Username:指定用户名

-W,--pwprompt:强制提示密码输入

-X,--xlogdir=XLOGDIR:指定事务日志的目录文件

[[email protected] data]$ ls

base    pg_clog       pg_dynshmem  pg_ident.conf  pg_multixact  pg_replslot  pg_snapshots  pg_stat_tmp  pg_tblspc    PG_VERSION  postgresql.auto.conf

global  pg_commit_ts  pg_hba.conf  pg_logical     pg_notify     pg_serial    pg_stat       pg_subtrans  pg_twophase  pg_xlog     postgresql.conf

6、配置postgresql.conf

允许服务监听范围,0.0.0.0允许监听所有 IPv4 地址

listen_addresses = ‘0.0.0.0‘

port = 10637

#用户访问日志格式

log_destination = ‘csvlog‘

#启用用户访问日志收集器

logging_collector = on

##指定运行日志存放路径,指定运行日志文件名称

log_directory = ‘/data/postgresql5.6/log‘

log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log‘

7、配置pg_hba.conf

#只给本地和192.168.0.0连接

host    all             all             127.0.0.1/32           md5

host    all             all             192.168.0.0/24         md5

8、配置Postgresql环境变量

在/etc/profile文件中增加下面内容

PGDATA=/data/postgresql5.6/data

PGHOST=127.0.0.1

PGDATABASE=postgres

PGUSER=postgres

PGPORT=10637

##PGPASSWORD="123456"

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

export PGDATA PGHOST PGDATABASE PGUSER PGPORT PATH PGPASSWORD

环境变量生效

[[email protected] postgresql-9.6]# source /etc/profile

[[email protected] postgresql-9.6]# which psql

/usr/local/pgsql9.6/bin/psql

9.下面配置postgresql的动态库到搜索路径中

[[email protected] postgresql-9.6]# vim /etc/ld.so.conf.d/pgsql.conf

/usr/local/pgsql/lib

搜索路径生效

[[email protected] postgresql-9.6]# ldconfig

[[email protected] jumpserver]#  ldconfig -p  | grep libpq

libpqwalreceiver.so (libc6,x86-64) => /usr/local/pgsql9.6/lib/libpqwalreceiver.so

libpq.so.5 (libc6,x86-64) => /usr/local/pgsql9.6/lib/libpq.so.5

libpq.so (libc6,x86-64) => /usr/local/pgsql9.6/lib/libpq.so

10、启动PostgreSQL服务

因为我们上面配置了环境变量,所以我们可以这样启动服务

[[email protected] postgresql-9.6.1]# su - postgres

[[email protected] postgresql-9.6]$ pg_ctl start

该命令与下面的语句是一样的效果

[[email protected] postgresql-9.6 ]$ /usr/local/pgsql9.6/bin/pg_ctl -D /data/postgresql5.6/data  start

时间: 2024-08-30 00:48:38

postgresql编译安装及配置的相关文章

php编译安装与配置

php编译安装与配置 =========================================== 官网:http://php.net/ 官网下载:http://php.net/downloads.php =========================================== 一:了解与准备 1.1:Apache(httpd) nginx 与 php 连接方式: httpd与php: 1:php 作为 httpd 模块 2:fastcgi(php-fpm) 3:cgi(

Emacs安装配置全攻略之一编译安装简单配置

/******************************************************************************************************************************************/ 原创作品,转载时请务必以超链接形式标明文章原始出处:http://blog.csdn.net/gqb_driver/article/details/29407717,作者:gqb666 /***************

libCURL开源库在VS2010环境下编译安装,配置详解

libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 CURL开源库VS2010环境下编译安装,配置详解 一 准备 1.1 CURL官网下载地址:http://curl.haxx.se/download.html 1.2 找到源码包,我这里下载的是7.32.0版:http://curl.haxx.se/download/curl-7.32.0.zip 二 步骤 2.1 打开curl-7.32.0\

CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动

CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动1.关于mysql?MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性.特点: Mysql是开源的,所以你不需要支付额外的费用.Mysql支持大型的数据库.可以处理拥有上千

postgresql编译安装与调试(二)

接前文postgresql编译安装与调试(一),继续说说postgresql的编译安装与调试. 上一篇已经详细说明了如何在Linux系统上编译安装postgresql,这次我们在此基础上简单讲讲如何在linux系统上调试和追踪代码. 我记得之前看过一篇关于posgresql的文章,postgresql最早只有20万左右的代码量,而如今已经过100万行了,如此巨大的代码量,在没有纲领的前提下简直是盲人摸象. 为方便调试工作,在进入具体的调试之前,我们先来好好了解下postgresql的代码体系结构

HA专题: 编译安装并配置DRBD

HA专题: 编译安装并配置DRBD 前言 上篇我们讲到使用corosync+pacemaker实现MySQL高可用, 但是NFS容易成为单点故障从而导致数据丢失等严重问题, 我们可以使用drbd来实现MySQL数据的高可用, 本文介绍如何编译安装drbd并配置drbd实现不同主机的分区镜像 实验环境 今天实验环境比较简单, 所以就不画图了 主机 IP 功用 node1.anyisalin.com 172.16.1.2 drbd节点 node2.anyisalin.com 172.16.1.3 d

Linux——CentOS 6.3下PostgreSQL 的安装与配置

一.简介 PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统.有些特性甚至连商业数据库 都不具备.这个起源于伯克利(BSD)的数据库研究计划目前已经衍生成一项国际开发项目,并且有非常广泛的用户. 二.系统环境 系统平台:CentOS release 6.3 (Final) PostgreSQL 版本:PostgreSQL 9.2.4 防火墙已关闭/iptables: Firewall is not runn

PostgreSQL编译安装

一.PostgreSQL简介 PostgreSQL是目前功能最强大的开源数据库,支持丰富的数据类型和自定义类型,且它提供了丰富的接口,可以轻易的扩展它的功能. 与其他数据库相比,PostgreSQL有以下优势: ●PostgreSQL是目前功能最强大的开源数据库 ●稳定可靠:PostgreSQL是唯一能做到数据零丢失的开源数据库 ●支持广泛:PostgreSQL支持大量的主流开发语言,包括C.C++.Perl.Python.Java.PHP等 ●社区活跃:基本上每三个月会推出一个新的补丁版本,这

CentOS 6.3下PostgreSQL 的安装与配置

一.简介 PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统.有些特性甚至连商业数据库都不具备.这个起源于伯克利(BSD)的数据库研究计划目前已经衍生成一项国际开发项目,并且有非常广泛的用户. 二.系统环境 系统平台:CentOS release 6.3 (Final) PostgreSQL 版本:PostgreSQL 9.2.4 防火墙已关闭/iptables: Firewall is not runni