设为首页 收藏本站
查看: 1621|回复: 0

[经验分享] postgresql编译安装及配置

[复制链接]

尚未签到

发表于 2017-11-7 10:39:51 | 显示全部楼层 |阅读模式
1、建立postgres用户
[iyunv@nfs source]# adduser postgres


2、下载postgresql源码
[iyunv@nfs source]# pwd

/home/postgres/source
[iyunv@nfs source]# wget https://ftp.postgresql.org/pub/s ... gresql-9.6.1.tar.gz

3、编译安装postgresql:
[iyunv@nfs source]# pwd

/home/postgres/source
[iyunv@nfs source]# tar zxf postgresql-9.6.1.tar.gz
[iyunv@nfs source]# cd postgresql-9.6.1
[iyunv@nfs postgresql-9.6.1]# ./configure --prefix=/usr/local/pgsql9.6.1
[iyunv@nfs postgresql-9.6.1]# gmake -j 8
[iyunv@nfs postgresql-9.6.1]# gmake install

4.初始化数据库:

mkdir -p /data/postgresql5.6/data
chown -R postgres.postgres /data/postgresql5.6/data
[iyunv@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

环境变量生效
[iyunv@nfs postgresql-9.6]# source /etc/profile

[iyunv@nfs postgresql-9.6]# which psql
/usr/local/pgsql9.6/bin/psql

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

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

/usr/local/pgsql/lib
搜索路径生效
[iyunv@nfs postgresql-9.6]# ldconfig

[iyunv@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服务
因为我们上面配置了环境变量,所以我们可以这样启动服务
[iyunv@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




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-406649-1-1.html 上篇帖子: PostgreSQL字符集问题导致乱码 下篇帖子: PostgreSQL多种方式安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表