检查PostgreSQL 是否已经安装

rpm -qa | grep postgres    检查PostgreSQL 是否已经安装
rpm -qal | grep postgres   检查PostgreSQL 安装位置

返回信息

[root@dn07 ~]# rpm -qa | grep postgres
postgresql-libs--.el7.x86_64
[root@dn07 ~]# rpm -qal | grep postgres
/usr/share/doc/postgresql-libs-
/usr/share/doc/postgresql-libs-/COPYRIGHT
/usr/lib/firewalld/services/postgresql.xml
/usr/lib64/security/pam_postgresok.so
/usr/share/doc/pam-/txts/README.pam_postgresok
/usr/share/.gz
/etc/selinux/targeted/active/modules//postgresql
/etc/selinux/targeted/active/modules//postgresql/cil
/etc/selinux/targeted/active/modules//postgresql/hll
/etc/selinux/targeted/active/modules//postgresql/lang_ext

若已经安装,则使用rpm -e 命令卸载

[root@dn07 ~]# rpm -e postgresql-libs--.el7.x86_64
     error: Failed dependencies:
        libpq.so.()(64bit) is needed by (installed) python-psycopg2--.el7.x86_64
[root@dn07 ~]# rpm -e python-psycopg2--.el7.x86_64
[root@dn07 ~]# rpm -e postgresql-libs--.el7.x86_64

可以使用rpm -qa | grep postgres再次查看是否还有Postgres安装文件,没有卸载完成

使用yum 出现 Loaded plugins: fastestmirror

解决方法:https://www.cnblogs.com/lzcys8868/p/8184681.html

bash: wget: command not found的两种解决方法

解决方法:https://www.cnblogs.com/areyouready/p/8909665.html

Install the repository RPM:

yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

Install the client packages:

yum install postgresql96

Optionally install the server packages:

yum install postgresql96-server

可以使用rpm -qal|grep postgres这个命令查看安装文件的位置,注意默认的postgresql配置文件的位置和名称(带有版本号)

[root@dn08 ~]# rpm -qal|grep postgres
/usr/share/doc/postgresql96-
/usr/share/doc/postgresql96-/COPYRIGHT
/usr/share/doc/postgresql96-/KNOWN_BUGS
……
/usr/pgsql-9.6/share/postgres.description
/usr/pgsql-9.6/share/postgres.shdescription
/usr/pgsql-9.6/share/postgresql.conf.sample
/var/run/postgresql

切换postgres用户执行初始化数据库操作

新增postgres用户组:

groupadd postgres

新增postgres用户并且设置这个用户属于上面创建的postgres用户组:

useradd -g postgres postgres

修改postgres用户密码:passwd postgres(这里设置密码为123):

passwd postgres  --修改postgres用户密码

Postgresql不能以root身份初始化,要以postgres用户的身份运行:

su postgres  切换用户

初始化数据库:

/usr/pgsql-9.6/bin/postgresql96-setup initdb -E UNICODE -D /mnt/pgsql/data --初始化数据库

错误!!!

依然转换为root用户初始化并启动数据库:

su root
/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl start postgresql-9.6

进入数据库存放位置,查询初始化数据库成功之后的目录内容:

cd /var/lib/pgsql/9.6/data
ll

返回目录信息:

drwx------  postgres postgres     3月   : base
drwx------  postgres postgres   3月   : global
drwx------  postgres postgres      3月   : log
drwx------  postgres postgres     3月   : pg_clog
drwx------  postgres postgres      3月   : pg_commit_ts
drwx------  postgres postgres      3月   : pg_dynshmem
-rw-------  postgres postgres   3月   : pg_hba.conf
-rw-------  postgres postgres   3月   : pg_ident.conf
drwx------  postgres postgres     3月   : pg_log
drwx------  postgres postgres     3月   : pg_logical
drwx------  postgres postgres     3月   : pg_multixact
drwx------  postgres postgres     3月   : pg_notify
drwx------  postgres postgres      3月   : pg_replslot
drwx------  postgres postgres      3月   : pg_serial
drwx------  postgres postgres      3月   : pg_snapshots
drwx------  postgres postgres      3月   : pg_stat
drwx------  postgres postgres     3月   : pg_stat_tmp
drwx------  postgres postgres     3月   : pg_subtrans
drwx------  postgres postgres      3月   : pg_tblspc
drwx------  postgres postgres      3月   : pg_twophase
-rw-------  postgres postgres      3月   : PG_VERSION
drwx------  postgres postgres     3月   : pg_xlog
-rw-------  postgres postgres     3月   : postgresql.auto.conf
-rw-------  postgres postgres  3月   : postgresql.conf
-rw-------  postgres postgres     3月   : postmaster.opts
-rw-------  postgres postgres     3月   : postmaster.pid

编辑postgresql.conf文件,修改数据库默认接收的监听地址与端口参数:

cat postgresql.conf | grep -n listen_addresses  查找listen_addresses在postgresql.conf文件中的位置并显示行号
vi postgresql.conf 编辑postgresql.conf文件

去掉59行的注释,将listen_addresses = 'localhost' 改成 listen_addresses = '*',下图是修改后listen_addresses的值:

接下来继续修改pg_hba.conf文件,告诉数据库服务器它将允许什么样的客户端连接到自己:

vi pg_hba.conf --修改postgresql服务连接文件

在末尾增加一行,表示允许任何一个客户端使用正确的用户名和密码访问自己:

host    all             all                            trust

查看postgresql是否运行:

ps -ef | grep postgres  查看postgres的进程信息

开始连接postgresql数据库:

psql -U postgres //连接pgsql server

psql: 致命错误:  对用户"postgres"的对等认证失败

继续修改pg_hba.conf文件,将认证方式统一修改为trust(关于认证方式的说明见:http://www.cnblogs.com/EasonJim/p/9057867.html),并执行命令重启postgresql

/usr/pgsql-9.6/bin/pg_ctl restart -D /var/lib/pgsql/9.6/data

其中postgresql的执行文件目录为/usr/pgsql-9.6/bin,目录下包含以下程序:

-rwxr-xr-x  root root    2月   : clusterdb
-rwxr-xr-x  root root    2月   : createdb
-rwxr-xr-x  root root    2月   : createlang
-rwxr-xr-x  root root    2月   : createuser
-rwxr-xr-x  root root    2月   : dropdb
-rwxr-xr-x  root root    2月   : droplang
-rwxr-xr-x  root root    2月   : dropuser
-rwxr-xr-x  root root   2月   : initdb
-rwxr-xr-x  root root    2月   : pg_archivecleanup
-rwxr-xr-x  root root    2月   : pg_basebackup
-rwxr-xr-x  root root   2月   : pgbench
-rwxr-xr-x  root root    2月   : pg_config
-rwxr-xr-x  root root    2月   : pg_controldata
-rwxr-xr-x  root root    2月   : pg_ctl
-rwxr-xr-x  root root   2月   : pg_dump
-rwxr-xr-x  root root    2月   : pg_dumpall
-rwxr-xr-x  root root    2月   : pg_isready
-rwxr-xr-x  root root    2月   : pg_receivexlog
-rwxr-xr-x  root root    2月   : pg_resetxlog
-rwxr-xr-x  root root   2月   : pg_restore
-rwxr-xr-x  root root    2月   : pg_rewind
-rwxr-xr-x  root root    2月   : pg_test_fsync
-rwxr-xr-x  root root    2月   : pg_test_timing
-rwxr-xr-x  root root   2月   : pg_upgrade
-rwxr-xr-x  root root    2月   : pg_xlogdump
-rwxr-xr-x  root root  2月   : postgres
-rwxr-xr-x  root root     2月   : postgresql96-check-db-dir
-rwxr-xr-x  root root     2月   : postgresql96-setup
lrwxrwxrwx  root root        3月   : postmaster -> postgres
-rwxr-xr-x  root root   2月   : psql
-rwxr-xr-x  root root    2月   : reindexdb
-rwxr-xr-x  root root    2月   : vacuumdb

其中postgresql的数据文件目录为/var/lib/pgsql/9.6/data,目录下包含以下内容:

drwx------  postgres postgres     3月   : base
drwx------  postgres postgres   3月   : global
drwx------  postgres postgres      3月   : log
drwx------  postgres postgres     3月   : pg_clog
drwx------  postgres postgres      3月   : pg_commit_ts
drwx------  postgres postgres      3月   : pg_dynshmem
-rw-------  postgres postgres   3月   : pg_hba.conf
-rw-------  postgres postgres   3月   : pg_ident.conf
drwx------  postgres postgres     3月   : pg_log
drwx------  postgres postgres     3月   : pg_logical
drwx------  postgres postgres     3月   : pg_multixact
drwx------  postgres postgres     3月   : pg_notify
drwx------  postgres postgres      3月   : pg_replslot
drwx------  postgres postgres      3月   : pg_serial
drwx------  postgres postgres      3月   : pg_snapshots
drwx------  postgres postgres      3月   : pg_stat
drwx------  postgres postgres     3月   : pg_stat_tmp
drwx------  postgres postgres     3月   : pg_subtrans
drwx------  postgres postgres      3月   : pg_tblspc
drwx------  postgres postgres      3月   : pg_twophase
-rw-------  postgres postgres      3月   : PG_VERSION
drwx------  postgres postgres     3月   : pg_xlog
-rw-------  postgres postgres     3月   : postgresql.auto.conf
-rw-------  postgres postgres  3月   : postgresql.conf
-rw-------  postgres postgres     3月   : postmaster.opts
-rw-------  postgres postgres     3月   : postmaster.pid

再次登录:

psql -U postgres

登录成功,出现以下界面:

[root@dn08 ~]# psql -U postgres
psql ()
输入 "help" 来获取帮助信息.

postgres=#

在Centos上安装Postgre SQL的更多相关文章

  1. NoSql1 在Linux(CentOS)上安装memcached及使用

    前言:       今天是初五,生活基本要从过年的节奏中回归到正常的生活了,所以想想也该想想与工作有关的事情了.我之前在工作中会经常使用memcached和redis,但是自己一直没有时间系统的好好看 ...

  2. 在Ubuntu|CentOS上安装Shutter截图工具及快捷键设置

    简介 Shutter前身叫GScrot,它是一款相当棒的截图软件. 通过Shutter,你可以截取包括选定区域.全屏幕.窗口.窗口内的控件甚至网页的图像.通过内置的强大插件机制,你可以在截图后,对图像 ...

  3. 在CentOS上安装rabbitmq-server

    ***在 CentOS 6.4上安装python*** 注意啊,自己手动安装python2.7.5,不要动系统上面其他的版本 1,先安装GCC,用如下命令yum install gcc gcc-c++ ...

  4. CentOS上安装软件错误提示:configure: error: no acceptable C compiler found in $PATH

    CentOS上安装软件错误提示:configure: error: no acceptable C compiler found in $PATH 因为是centos linux,默认可以采用yum方 ...

  5. 如何在centos上安装epel源

    一.EPEL是什么? EPEL (Extra Packages for Enterprise Linux,企业版Linux的额外软件包) 是Fedora小组维护的一个软件仓库项目,为RHEL/Cent ...

  6. 在Centos上安装RabbitMQ流程(转)

    在Centos上安装RabbitMQ流程------------------------ 1. 需求 由于项目中要用到消息队列,经过ActiveMQ与RabbitMQ的比较,最终选择了RabbbitM ...

  7. 在CentOS上安装ZooKeeper集群

    一共准备3个CentOS虚拟机 172.16.9.194 172.16.9.195 172.16.9.196 上传zookeeper-3.3.6.tar.gz到服务器并解压,3台服务器的目录结构如下 ...

  8. CentOS上安装Node.js

    CentOS上安装Node.js [日期:2014-07-21] 来源:Linux社区  作者:maskdfe [字体:大 中 小]     CentOS上安装Node.js(想在Linux上学习No ...

  9. Linux系统入门学习:在CentOS上安装phpMyAdmin

    问题:我正在CentOS上运行一个MySQL/MariaDB服务,并且我想要通过网络接口来用phpMyAdmin来管理数据库.在CentOS上安装phpMyAdmin的最佳方法是什么? phpMyAd ...

随机推荐

  1. dk7和jdk8的一些新特性

    本文是我学习了解了j 的一些资料,有兴趣的大家可以浏览下下面的内容. 官方文档:http://www.oracle.com/technetwork/java/javase/jdk7-relnotes- ...

  2. 将项目打成war包并用tomcat部署的方法,步骤及注意点

    部署的遇到第一个问题,就是tomcat和jdk的环境问题: 首先 理解为啥要关注这二者的环境呢?他们还是有关系的–tomcat 作为比较流行的java Web服务器也是用java来实现的一个比较大的软 ...

  3. Python3问题TypeError: object() takes no parameters

    1. Python中关键字变量和特殊函数,都是以__xxx__来表示的 初学Python的朋友,需要注意其中变量名中前后是有两个下划线(_)的,如果不注意,调用内部关键字变量和特殊函数时,将会出现错误 ...

  4. 解密国内BAT等大厂前端技术体系-美团点评之下篇(长文建议收藏)

    引言 在上篇中,我已经介绍了美团点评的业务情况.大前端的技术体系,其中大前端的技术全景图如下: 上篇重点介绍了工程化和代码质量的部分,工程化涵盖了客户端持续集成平台-MCI.全端监控平台-CAT.移动 ...

  5. Web基础了解版07-EL表达式-运算符-11个隐式对象

    EL EL(Expression Language)是JSP内置的表达式语言,用以访问页面的上下文以及不同作用域中的对象 ,取得对象属性的值,或执行简单的运算或判断操作.EL在得到某个数据时,会自动进 ...

  6. celery参考

    1,https://www.wandouip.com/t5i377365/ 2,https://www.cnblogs.com/zhangmingcheng/p/6050270.html (syste ...

  7. PS——牛奶字

    一.新建800*600像素的背景,设置前景色到透明渐变(黑到白),线性渐变,从上到下画一条直线 二.用矩形选框工具在背景上方1/2位置画一个矩形,Ctrl+Delete填充颜色 三.输入文字,设置图层 ...

  8. 【转】Docker网络模式--默认模式bridge模式

    一 引言 当 Docker 启动时,会自动在主机上创建一个名为 docker0 虚拟网桥,这实际上就是 Linux 的一个 bridge,可以理解为一个软件交换机.它会在挂载到它的网口之间进行转发.系 ...

  9. ASP.NET Core搭建多层网站架构【2-公共基础库】

    2020/01/28, ASP.NET Core 3.1, VS2019,Newtonsoft.Json 12.0.3, Microsoft.AspNetCore.Cryptography.KeyDe ...

  10. 数据结构--Java语言描述

    本篇文章是为了记录自己在学习数据结构时的笔记,会对常见的数据结构做基本的介绍以及使用Java语言进行实现.包括 动态数组 栈 队列 链表 二分搜索树 优先队列和堆 线段树 Trie树 并查集 AVL树 ...