微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PostgreSQL源码安装


Postgresql 源码安装


下载Postgresql安装包


wget https://ftp.postgresql.org/pub/source/v9.5.7/postgresql-9.5.7.tar.gz


官网下载

https://www.postgresql.org/ftp/source/


安装依赖包

yum -y install readline-devel zlib-devel


解包-配置-编译-安装

tar -xf postgresql-9.5.7.tar.gz

cd postgresql-9.5.7

./configure --prefix=/usr/local/postgresql

make && make install


认超级用户(root)不能启动postgresql

useradd postgres

mkdir -p /data/postgresql/data

mkdir -p /data/postgresql/data/log

chown -R postgres:postgres /usr/local/postgresql/

chown -R postgres:postgres /data/postgresql/data/


为了方便,设置postgres环境变量

su - postgres //切换到postgres用户

[postgres@localhost ~]$ vim .bash_profile

#.bash_profile

#Getthealiasesandfunctions
if[-f~/.bashrc];then
.~/.bashrc
fi

#Userspecificenvironmentandstartupprograms

PGHOME=/usr/local/postgresql#psql安装目录
exportPGHOME
PGDATA=/data/postgresql/data#数据库目录
exportPGDATA

PATH=$PATH:$HOME/bin:$HOME/.local/bin:$PGHOME/bin
exportPATH


source ./.bash_profile 使其立即生效


[postgres@localhost ~]$ which psql

/usr/local/postgresql/bin/psql

[postgres@localhost ~]$ psql -V

psql (Postgresql) 9.5.7


初始化数据库

initdb

Success. You can Now start the database server using: pg_ctl -D /data/postgresql/data -l logfile start


启动Psql

pg_ctl -D /data/postgresql/data -l /data/postgresql/data/log/postgres.log start


设置Postgresql密码,

[postgres@localhost data]$ psql

psql (9.5.7)

Type "help" for help.

postgres=# \password

Enter new password: //密码

Enter it again: //确认密码


修改Postgresql密码

[postgres@localhost data]$ psql

Password:

psql (9.5.7)

Type "help" for help.

postgres=# alter user postgres with password '123456';

ALTER ROLE

postgres=# \q


认psql本地登录是不需要密码的,即使我们设置了密码,也不需要密码就能登录。应为配置文件pg_hba.conf中的local设置为trust,为了安全我们修改为 password,就是使用密码才能登陆,(当我们忘记密码的时间,也可以使用这用方式,先设置为trust之后,修改密码,然后在设置为password。)


[postgres@localhost ~]$cd /data/postgresql/data

[postgres@localhost data]$ vim pg_hba.conf

localallallpassword#认trust,本地登录不要密码,设置为password使用密码登录。
hostallall0.0.0.0/0password#ip地址修改为0.0.0.0/0,


修改psql认端口

[postgres@localhost data]$ vim postgresql.conf

listen_addresses='*'#127.0.0.1只允许本地访问,设置为*允许整个网络。
port=5432#监听端口


修改后需要重启psql才能生效


pg_ctl -D /data/postgresql/data -l /data/postgresql/data/log/postgres.log restart

原文地址:https://www.jb51.cc/postgresql/193497.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐