postgresql编译安装及配置

本文涉及的产品
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介:

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
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
11月前
|
存储 关系型数据库 数据库
用Patroni配置PostgreSQL高可用集群
Patroni是Zalando开发的数据库高可用管理软件,用于编排和自动化PostgreSQL集群的管理过程。Patroni 需要一系列其他组件的支持,通过利用第三方分布式一致性软件,组建并实现数据库高可用方案。
用Patroni配置PostgreSQL高可用集群
|
11月前
|
关系型数据库 MySQL Nacos
nacos数据库使用PostgreSQL及集群配置
从Nacos2.2版本开始,Nacos提供了数据源扩展插件,以便让需要进行其他数据库适配的用户自己编写插件来保存数据。
|
27天前
|
关系型数据库 MySQL Linux
在Linux中,如何配置数据库服务器(如MySQL或PostgreSQL)?
在Linux中,如何配置数据库服务器(如MySQL或PostgreSQL)?
|
2月前
|
安全 关系型数据库 Linux
|
3月前
|
缓存 关系型数据库 数据库
postgresql.conf配置详解
postgresql.conf配置详解
|
11月前
|
安全 关系型数据库 Go
远程连接PostgreSQL:配置指南与安全建议
远程连接PostgreSQL:配置指南与安全建议
594 0
|
4月前
|
关系型数据库 网络安全 数据安全/隐私保护
你会开启Postgresql 的SSL单向认证 配置?
你会开启Postgresql 的SSL单向认证 配置?
123 0
你会开启Postgresql 的SSL单向认证 配置?
|
4月前
|
关系型数据库 Linux 数据安全/隐私保护
PostgreSQL【部署 02】在线安装PostgreSQL(Some psql features might not work 问题处理+角色密码设置+配置远程访问)
PostgreSQL【部署 02】在线安装PostgreSQL(Some psql features might not work 问题处理+角色密码设置+配置远程访问)
68 0
PostgreSQL【部署 02】在线安装PostgreSQL(Some psql features might not work 问题处理+角色密码设置+配置远程访问)
|
4月前
|
监控 关系型数据库 Java
SpringBoot【集成 01】Druid+Dynamic+Greenplum(实际上用的是PostgreSQL的驱动)及 dbType not support 问题处理(附hikari相关配置)
SpringBoot【集成 01】Druid+Dynamic+Greenplum(实际上用的是PostgreSQL的驱动)及 dbType not support 问题处理(附hikari相关配置)
243 0
|
9月前
|
关系型数据库 数据库 PostgreSQL
flink postgresql cdc实时同步(含pg安装配置等)
flink postgresql cdc实时同步(含pg安装配置等)
348 0