CentOS安装
rpm -Uhh https://mirrors.aliyun.com/postgresql/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sed -i "s@https://download.postgresql.org/pub@https://mirrors.aliyun.com/postgresql@g" /etc/yum.repos.d/pgdg-redhat-all.repo
cd /etc/yum.repos.d/
mv pgdg-redhat-all.repo pgdg-redhat-all.repo.old
yum update -y
yum search postgresql
yum install postgresql.x86_64 postgresql-server.x86_64 postgresql-contrib.x86_64
新建数据库
find / -name initdb //查找initdb地址,地址为/usr/bin/initdb
/usr/bin/initdb -E UNICODE -D /home/postgres/pgsql/data
配置
postgresql.conf
listen_addresses = '*'
port = 5432
pg_hba.conf
host all all 0.0.0.0/0 password
启动
pg_ctl start -D /home/postgres/pgsql/data -l /home/postgres/pgsql/dataserver.log
pg_ctl stop -D /home/postgres/pgsql/data
连接数据库
psql -h localhost -p 5432 -U postgres -l
修改密码
ALTER USER postgres PASSWORD 'newpassword';
开发时驱动安装
centOS: yum install postgresql-devel
Ubuntu-based: sudo apt-get install libpq-dev
参考文档
https://www.cnblogs.com/qiyebao/p/4562557.html