标签:pgsql postgresql service Centos7 systemctl yum 9.4 安装
本文版本:Centos7.4和Postgresql9.4
1.查找需要安装的版本:
https://yum.postgresql.org/repopackages.php
2.使用root用户登录,安装yum源:
yum install https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm
下载路径为:
[root@localhost yum-root-v9tlUe]# pwd /var/tmp/yum-root-v9tlUe
[root@localhost yum-root-v9tlUe]# ls pgdg-centos94-9.4-3.noarch.rpm
3.安装Postgresql
yum install -y postgresql94-server postgresql94-contrib
初始化数据库:
查看数据库有没有初始化
ll -lhtr /var/lib/pgsql/9.4/data/
如果初始化过,把之前的数据库删除掉,在初始化。
rm -rf /var/lib/pgsql/9.4/data/* /var/lib/pgsql /usr/pgsql-9.4
初始化:
/usr/pgsql-9.4/bin/postgresql94-setup initdb
4.修改Postgresql用户密码(安装完之后,会自动生成一个postgres用户)
切换postgres用户:
su - postgres
登录数据库:
psql -U postgres
可能会出现以下错误:(重启psql再进入,systemctl restart postgresql-9.4.service)
更新密码:
ALTER USER postgres with encrypted password 'abc123';
5.配置远程访问:
vi /var/lib/pgsql/9.4/data/postgresql.conf
找到listen_addresses = 'localhost' ,将 localhost 改为 *
vi /var/lib/pgsql/9.4/data/pg_hba.conf
如果允许本地项目访问,将local、IPv4、IPv6的peer改为trust
并在IPv4增加一行:
host all all 0.0.0.0/0 md5
重启服务:
systemctl restart postgresql-9.4.service
防火墙设置:
firewall-cmd --add-service=postgresql --permanent
firewall-cmd --reload
可以用其他工具连接。
6.相关命令
systemctl restart postgresql-9.4.service #重启服务 systemctl enable postgresql-9.4.service #设置开机自启 systemctl start postgresql-9.4.service #开启服务 systemctl status postgresql-9.4.service #查看服务状态
数据库相关操作:
\q #退出postgresql \l #查看所有数据库
\dt #查看数据库表
\d test #查看表结构
\c dbname #切换数据库 \i /pathA/xxx.sql #执行某个sql文件
标签:pgsql,postgresql,service,Centos7,systemctl,yum,9.4,安装 来源: https://www.cnblogs.com/Yatces/p/11082061.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。