开发者社区> 科技小能手> 正文

postgresql编译安装及配置

简介:
+关注继续查看

1、建立postgres用户

[root@nfs source]# adduser postgres


2、下载postgresql源码

[root@nfs source]# pwd

/home/postgres/source

[root@nfs source]# wget https://ftp.postgresql.org/pub/source/v9.6.1/postgresql-9.6.1.tar.gz


3、编译安装postgresql:

[root@nfs source]# pwd

/home/postgres/source

[root@nfs source]# tar zxf postgresql-9.6.1.tar.gz

[root@nfs source]# cd postgresql-9.6.1

[root@nfs postgresql-9.6.1]# ./configure --prefix=/usr/local/pgsql9.6.1 

[root@nfs postgresql-9.6.1]# gmake -j 8

[root@nfs postgresql-9.6.1]# gmake install


4.初始化数据库:

mkdir -p /data/postgresql5.6/data

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

[root@nfs postgresql-9.6.1]# su - postgres

[postgres@cacti data]$ 

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


[postgres@cacti 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:指定事务日志的目录文件


[postgres@cacti 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

环境变量生效

[root@nfs postgresql-9.6]# source /etc/profile

[root@nfs postgresql-9.6]# which psql

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


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

[root@nfs postgresql-9.6]# vim /etc/ld.so.conf.d/pgsql.conf 

/usr/local/pgsql/lib

搜索路径生效

[root@nfs postgresql-9.6]# ldconfig 

[root@cacti 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服务

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

[root@nfs postgresql-9.6.1]# su - postgres

[postgres@nfs postgresql-9.6]$ pg_ctl start

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

[postgres@nfs postgresql-9.6 ]$ /usr/local/pgsql9.6/bin/pg_ctl -D /data/postgresql5.6/data  start




 本文转自 wjw555 51CTO博客,原文链接:http://blog.51cto.com/wujianwei/1978825

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
RDS SQL Server通过配置镜像为高性能模式提高写入性能
RDS SQL Server通过配置镜像为高性能模式提高写入性能
175 0
1 PostgreSQL系统概述与编译安装|学习笔记
快速学习1 PostgreSQL系统概述与编译安装
135 0
一、postgresql安装与配置
postgresql数据库安装可主要分为两种,一种是apt快速安装,一种是二进制安装。本次安装我们将一一记录这两种安装步骤。
273 0
基于阿里云 RDS For MySQL 的配置与使用|学习笔记
快速学习基于阿里云 RDS For MySQL 的配置与使用
150 0
Postgresql服务配置|学习笔记
快速学习Postgresql服务配置
35 0
PostgreSQl 12主从流复制及归档配置
PostgreSQl 12主从流复制及归档配置
221 0
PostgreSQL 在windows 配置
PostgreSQL 在windows 配置
51 0
LXJ
PostgreSQL recovery.conf恢复配置
PostgreSQL recovery.conf恢复配置
222 0
PostgreSQL安装、配置及简单使用方法
一、PostgreSQL简介 1、什么是PostgreSQL PostgreSQL数据库是目前功能最强大的开源数据库,支持丰富的数据类型(如JSON何JSONB类型,数组类型)和自定义类型。而且它提供了丰富的接口,可以很容易地扩展它的功能,如可以在GiST框架下实现自己的索引类型等,它还支持使用C语言写自定义函数、触发器,也支持使用流行的语言写自定义函数,比如其中的PL/Perl提供了使用Perl语言写自定义函数的功能,当然还有PL/Python、PL/Tcl,等等。 2、PostgreSQL数据库的优势 PostgreSQL数据库是目前功能最强大的开源数据库,它是最接近工业标准SQL
736 0
+关注
科技小能手
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
金融级 PostgreSQL监控及优化
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
相关镜像