Ubuntu postgres 内网 安装 卸载

# 不能连接外网, 安装pg的过程

tar包下载地址 https://www.postgresql.org/ftp/source/v11.1/
放在/home/sxy 目录(随便放)
cd /home/sxy
tar xvzf postg*tar.gz
cd postg*
mkdir /usr/local/pgsql # 安装目录
./configure --prefix=/usr/local/pgsql # 设置配置环境

Ubuntu 16.04报错(联网解决): (cent os 7 没有安装过)
configure: error: readline library not found
解决办法:sudo apt-get install libreadline6-dev
可能其他错误:
configure: error: zlib library not found
apt-get install zlib1g-dev

configure: configure: error: no acceptable C compiler found in $PATH
apt-get install gcc

./configure --prefix=/usr/local/pgsql # 再次配置环境
make && make install # 编译并安装, 出错会退出 (具体问题再baidu)
提示: Postgresql installation complete # 表示安装成功
ls -l /usr/local/pgsql/ # 会有4个目录(bin, include, lib 和 share) # 也说明安装成功
rm -rf /home/sxy/postg*

启动:
root 用户不能启动postgresql # (连接的时候会提示失败)原因baidu
修改密码:
passwd postgres # Ubuntu pg11默认安装了postgres 用户

mkdir -p /var/postgresql/data # 经常变动
初始化:
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
touch /var/postgresql/logfile
chown postgres:postgres /var/postgresql/*
chown postgres:postgres /usr/local/pgsql/*
chmod -R 0700 /var/postgresql/*
修改配置文件:
vim /var/postgresql/data/postgresql.conf
listen_addresses = '*'
port = 5432
max_connections = 2000 # 改大点, 但用的时候还是要创建连接池

vim /var/postgresql/data/pg_hba.conf
添加:
host all all 0.0.0.0/0 md5
# (留下local)其他全注释

修改密码:
passwd postgres
su postgres
/usr/local/pgsql/bin/pg_ctl -D /var/postgresql/data/ -l logfile restart/start/stop # 启动数据库
/usr/local/pgsql/bin/psql -h ip # 本地连接数据库

猜你喜欢

转载自www.cnblogs.com/520zm/p/10261513.html