centos7安装postgresql,yum install postgresql,版本是9.2.7
安装后,初始化数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb //根据具体版本来
然后(这里参考https://blog.csdn.net/DaSo_CSDN/article/details/75330009)
systemctl enable postgresql
systemctl start postgresql失败,
systemctl status postgresql提示要先初始化数据库,日志中有命令
查看服务启动脚本/usr/lib//usr/lib/systemd/system/postgresql.service,当中:
约定了data目录PGDATA=/var/lib/pgsql/data和监听端口PGPORT=5432
----------------------------------11版本安装--------------------------------------------
# 下载rpm包
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-redhat11-11-2.noarch.rpm -y
# 安装
yum -y install postgresql11 postgresql11-server postgresql11-libs
# 初始化数据库
/usr/pgsql-11/bin/postgresql-11-setup initdb
# 设置开机自启动PostgreSQL和启动服务
systemctl enable postgresql-11
systemctl start postgresql-11
systemctl status postgresql-11
---------------------------------wsl 11安装-------------------------------------------------------------
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib #默认安装两个版本
sudo service postgresql start #默认启动两个版本
/etc/postgresql/版本/main/是配置文件目录,修改postgresql.conf,将11版本的端口改成5432,10版本的改为5433
sudo service postgresql start 11 #启动11版本
from:https://www.jianshu.com/p/018922b9ad31
and:https://www.jianshu.com/p/0dea2a45e2de
---------------------------------------------------------------------------------------------------------------
到data目录下
修改postgresql.conf,查找#listen_addresses = 'localhost',改成
listen_addresses = '*'
修改pg_hba.conf,IPV4连接,改成这样
# IPv4 local connections: host all all 127.0.0.1/32 trust host all all 0.0.0.0/0 password
参考
https://www.cnblogs.com/qiyebao/p/4562557.html
trust,本地可以使用psql -U postgres直接登录服务器;
peer,本地可以使用psql -h 127.0.0.1 -d postgres -U postgres直接登录服务器;
本地登录:
psql -U postgres //连接pgsql server
psql -h 127.0.0.1 -d postgres -U postgres //连接pgsql server
刷新配置
select pg_reload_conf();
显示一个新配置:
show data_directory;
为默认数据库账户postgres设置密码
select * from pg_shadow;
ALTER USER postgres WITH PASSWORD '1234'; //添加密码 select * from pg_shadow;
q回车 退出登录
防火墙打开5432端口
iptables -I INPUT -p tcp --dport 5432 -j ACCEPT service iptables save service iptables restart
----------------------操作数据库实例------------------------
https://blog.csdn.net/skh2015java/article/details/78814774
https://o-my-chenjian.com/2018/11/24/CRUD-Of-PostgreSQL-By-Golang/
https://blog.csdn.net/u013210620/article/details/82702114#GoPostgreSQLgithubcomlibpq_193
https://segmentfault.com/a/1190000018812714
-----------------------------------
监控指标的一个说明
https://www.influxdata.com/blog/metrics-to-monitor-in-your-postgresql-database/