资讯专栏INFORMATION COLUMN

Mac下安装Postgresql数据库

hosition / 1774人阅读

摘要:前言在安装数据库之前,需要先使用命令查看之前是否安装过。例如之前安装过版本,第二次又安装了版本,会导致最后的时候数据库无法启动并报错当存在两个版本冲突时,我采用的解决方式是直接使用命令删除安装的两个版本数据库,重新安装。

前言

在安装Postgresql数据库之前,需要先使用 brew list 命令查看之前是否安装过Postgresql。
例如之前安装过Postgresql 10.1版本,第二次又安装了Postgresql 11.2版本,会导致最后的时候数据库无法启动并报错:

“2019-05-09 19:16:31.378 CST [99652] DETAIL:  The data directory was initialized by PostgreSQL version 10, which is not compatible with this version 11.2.”

当存在两个版本冲突时,我采用的解决方式是直接使用brew uninstall postgresql命令删除安装的两个版本数据库,重新安装。

【当然,这种方式时候由于数据库本身没有重要数据,不建议,只因未用的时候暂未找到更好的方式】

安装命令
1、brew install postgresql -v
2、initdb /usr/local/var/postgres
3、brew services start postgresql

在Postgresql安装成功之后,会出现如下提示:

To restart postgresql after an upgrade:
brew services restart postgresql
Or, if you don"t want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start

提示说明可以使用brew services resstart postgresql启动Postgresql 服务或者使用 pg_ctl -D /usr/local/var/postgres start启动Postgresql,这里我使用的是第一个

Question1:
如果安装过Postgresql数据库,会存在/usr/local/var/postgres这样一个目录,再次安装数据库,使用initdb /usr/local/var/postgres 初始化数据库会出现如下提示,导致无法连接数据库终端

initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".

Answer:
可以将之前的目录移动到一个新的创建的目录下 mv /usr/local/var/postgres /usr/local/var/postgres1或者直接删除,再使用initdb /usr/local/var/postgres 命令重新初始化数据库

Result:

charodeacBook-Air:~ charo$ mv /usr/local/var/postgres /usr/local/var/postgres1  #
charodeMacBook-Air:~ charo$ initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "charolim".
This user must also own the server process.

The database cluster will be initialized with locale "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /usr/local/var/postgres -l logfile start

charodeMacBook-Air:~ charo$

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /usr/local/var/postgres -l logfile start

charodeMacBook-Air:~ charo$ psql
psql (11.2)
Type "help" for help.

charo=#

退出数据库可以使用q

                                                 Datetime:2019.5.09 亲测

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39044.html

相关文章

  • Mac安装Postgresql据库

    摘要:前言在安装数据库之前,需要先使用命令查看之前是否安装过。例如之前安装过版本,第二次又安装了版本,会导致最后的时候数据库无法启动并报错当存在两个版本冲突时,我采用的解决方式是直接使用命令删除安装的两个版本数据库,重新安装。 前言 在安装Postgresql数据库之前,需要先使用 brew list 命令查看之前是否安装过Postgresql。例如之前安装过Postgresql 10.1版...

    Dongjie_Liu 评论0 收藏0
  • 据库 | postgresql 安装

    摘要:当前项目是使用框架搭建接口层的业务,数据库端使用了,这里只是简单记录下自己的安装流程,因为开发机器使用的,所以流程只是针对。 当前项目是使用 django 框架搭建接口层的业务,数据库端使用了 postgresql,这里只是简单记录下自己的安装流程,因为开发机器使用的 mac,所以流程只是针对 mac。 1 软件管理工具 这里我使用的 homebrew,这个工具就不多说了,没有用过的可...

    Channe 评论0 收藏0
  • 使用docker部署PostgreSQL据库

    摘要:解决了服务器应用快速部署的问题。解决方案是自己装一个第二点,确保镜像服务器跑起来。你需要将真机的端口和虚拟机端口进行绑定,这样可以通过访问镜像服务器在真机上的端口,访问到数据库端口,进入镜像之中。 关于Docker的基本原理 原理上, 深入浅出Docker 一文讲的语言会更科学,我只捡不一定准确但直观而符合表面理解的一些讲一下。 Docker提供了基于操作系统级和应用级虚拟化的应用部署...

    singerye 评论0 收藏0
  • 使用docker部署PostgreSQL据库

    摘要:解决了服务器应用快速部署的问题。解决方案是自己装一个第二点,确保镜像服务器跑起来。你需要将真机的端口和虚拟机端口进行绑定,这样可以通过访问镜像服务器在真机上的端口,访问到数据库端口,进入镜像之中。 关于Docker的基本原理 原理上, 深入浅出Docker 一文讲的语言会更科学,我只捡不一定准确但直观而符合表面理解的一些讲一下。 Docker提供了基于操作系统级和应用级虚拟化的应用部署...

    Loong_T 评论0 收藏0
  • 「Odoo 基础教程系列」第一篇——环境准备

    摘要:安装好后,在中执行查看版本信息,应该会看到输出如下信息版本号可能会不同如果提示未找到,则需要手动将用户基础目录下的添加到中。相关文章基础教程系列第篇开天坑啦 showImg(https://segmentfault.com/img/bV4GZu?w=1262&h=911); 之前说好的 「Odoo 基础教程系列」终于来了(撒花)~刚过完年重新投入到工作中,一下子事情有点多都要忙不过来了...

    szysky 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<