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

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...