不使用默认用户postgres安装PostgreSQL详细步骤

本文介绍了如何在PostgreSQL中启用远程访问。需要修改postgresql.conf的listen_addresses设置为'*',并在pg_hba.conf中添加或修改配置为允许所有IP(0.0.0.0/0)或特定IP的md5验证远程连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

常见错误及解决方案:

报错:configure: error: readline library not found
解决方法:yum -y install readline-devel
报错:configure: error: no acceptable C compiler found in $PATH
解决方法:yum -y install gcc
报错:configure: error: zlib library not found
解决方法:yum install zlib-devel
报错:make: command not found
解决方法:yum -y install automake autoconf libtool make
注意事项:data文件夹不能放在postgres 用户权限之外的目录下。

安装步骤如下

./configure --prefix=/usr/local/IMX_pgsql
make
make install 
mkdir /usr/local/IMX_pgsql/data
chown imx:imx -R /usr/local/IMX_pgsql/
vi /usr/local/IMX_pgsql/data/postgresql.conf
su - imx 
initdb -D /usr/local/IMX_pgsql/data/
su root
chown imx:imx -R /usr/local/IMX_pgsql
vi /etc/sysconfig/iptables
cd /etc/rc.d/init.d
cp /postgresql-9.0.4/contrib/start-scripts/linux IMX_pgsql
chmod +x IMX_pgsql 
service IMX_pgsql start
su - imx 
pg_ctl -D /usr/local/IMX_pgsql/data -l /usr/local/IMX_pgsql/data/serverlog start
createuser -W imx_sql
    Shall the new role be a superuser? (y/n) n
    Shall the new role be allowed to create databases? (y/n) y
    Shall the new role be allowed to create more new roles? (y/n) n
createdb imx -O imx_sql
psql
    alter database imx owner to imx_sql;

这种方式安装的PostgreSQL可以随意移植到别的服务器上,继续使用

移植 Postgresql 到98 服务器上过程
1. 创建用户:useradd imx
2. 解压pgsql.tar.gz:
tar zxvf pgsql.tar.gz
3. 注册环境变量在home/postgres/.bash_profile 末尾追加

export PATH=$PATH:/usr/local/pgsql/bin

export MANPATH=$MANPATH:/usr/local/pgsql/man

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib


3. 复制linux到/etc/init.d,注册服务:cp /usr/local/pgsql/linux /etc/init.d/postgresql 
chkconfig --add postgresql
4. su postgresql 
5. 初始化数据库 initdb -D /usr/local/pgsql/data
6  切换到root 用户启动服务: service postgresql start

Postgresql允许远程访问配置修改

postgresql默认情况下,远程访问不能成功,如果需要允许远程访问,需要修改两个配置文件,说明如下:

1.postgresql.conf

将该文件中的listen_addresses项值设定为“*”,在9.0 Windows版中,该项配置已经是“*”无需修改。

2.pg_hba.conf

在该配置文件的host all all 127.0.0.1/32 md5行下添加以下配置,或者直接将这一行修改为以下配置

host    all    all    0.0.0.0/0    md5

如果不希望允许所有IP远程访问,则可以将上述配置项中的0.0.0.0设定为特定的IP值。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值