centos自带的postgresql
yum install postgresql
yum install postgresql-server
安装完成以后:可以搜索查找位置
which psql
which postgresql-setup
whereis postgresql-setup
安装完成会自动生成postgres用户,初始时,只能在该用户下使用,使用之前先初始化
postgresql-setup initdb
进入数据库目录:
/var/bin/psql
修改配置文件:/var/bin/psql/data/pg_hba.conf
local all all peer
修改为:
local all all trust
host all all 0.0.0.0/0 md5(远程)
远程连接:/var/bin/psql/data/postgresql.conf
去掉注释:修改listen_addresses属性为"*"
数据库启动 service postgresql start
然后第一次登陆:su - postgres
psql -u postgres
修改密码:\password
或者:alter user postgres with password ‘123456’
推出
\q
exit
centos 高版本安装
[root@localhost ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[root@localhost ~]# yum install -y postgresql11
[root@localhost ~]# yum install -y postgresql11-server
初始化[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
效果:
Initializing database … OK
设置外连接,修改端口:
[root@localhost ~]# vim /var/lib/pgsql/11/data/postgresql.conf
vim /var/lib/pgsql/11/data/pg_hba.conf
修改为
systemctl start postgresql-11