postgresql Linux 二进制文件安装

来源:互联网 发布:待优化商品是什么意思 编辑:程序博客网 时间:2024/05/18 02:54

一、创建psotgres用户
groupadd postgres
useradd -g postgres postgres


二、创建必须目录

下载路径https://www.enterprisedb.com/download-postgresql-binaries
wget https://get.enterprisedb.com/postgresql/postgresql-9.6.4-1-linux-x64-binaries.tar.gz

进入下载目录
tar -xzf postgresql-9.6.4-1-linux-x64-binaries.tar.gz -C /data/service


创建data目录:
mkdir -p /data/service/postgresql/data
mkdir -p /data/service/postgresql/log


授权:
chown -R postgres.postgres pgsql  (解压目录)
chown -R postgres.postgres postgresql


三、初始化


cd /data/service/pgsql/
su postgres


./bin/initdb -E utf8 -D /data/service/postgresql/data


四、启动
./postgres -D /data/service/postgresql/data/ > /data/service/postgresql/log/postgres.log &
 
 关闭
./pg_ctl -D /data/service/postgresql/data stop 
 
 
登录 
./psql -U pg -d mydb


----------------------
远程连接
1 修改pg_hba.conf文件
host  all    all    127.0.0.1/32     trust
host  all    all    192.168.1.0/24    md5


其中,数字24是子网掩码,表示允许192.168.1.0--192.168.1.255的计算机访问!


2 修改postgresql.conf文件,将数据库服务器的监听模式修改为监听所有主机发出的连接请求。


定位到#listen_addresses=’localhost’。PostgreSQL安装完成后,默认是只接受来在本机localhost的连接请 求。
将行开头都#去掉,将行内容修改为listen_addresses=’*'来允许数据库服务器监听来自任何主机的连接请求