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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |