问题描述
在官网(pgadmin官网-download)下载了pgadmin4之后打开,没有server
(当时图片没有截,就是server右边没有“(1)”)
自己添加server的时候获得错误提示:
psql: could not connect to server: Connection refused
Is the server running on host "server.joe.com" and accepting
TCP/IP connections on port 5432?
于是上网搜(现在回想可能是没有安装postgreSQL的问题),解决过程如下。
这个解决过程综合了多个博客的解决方式(感谢各位),由于担心之后如果重装系统需要重新走一遍这个步骤,特此记录。如中间有有问题的步骤,欢迎大佬指正。
解决过程
STEP_1 卸载pgadmin4
在应用程序里把pgadmin扔到废纸篓
STEP_2 安装Homebrew
参考博客: https://blog.csdn.net/Li_yi_kun/article/details/83821899?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control&dist_request_id=1328680.12035.16161572481655225&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control
1、安装Xcode Command Line Tools
先安装Homebrew ,但是Homebrew依赖于Xcode Command Line Tools,所以需先打开终端执行:
xcode-select --install
2、通过镜像安装Homebrew
应该是推荐从官网(Homebrew官网)复制命令到命令行的(如下图中间那行,点命令右边的小图标可以直接复制)。
但是我因为解决不了如下问题(好像是网络问题),选择了镜像安装。
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out
以下这步参考:
https://zhuanlan.zhihu.com/p/90508170
在命令行里输入:
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
然后等待安装
检查是否安装成功
$ brew -v
STEP_3 Homebrew 安装 PostgreSQL
1、 安装PostgreSQL
brew install postgresql
然后等待安装(晚上装了好久,但是早上一下就好了,玄学事件。)
2、数据库初始化
在运行这个命令的时候遇到问题
initdb /usr/local/var/postgres -E utf8
The database cluster will be initialized with locale "zh_CN.UTF-8".
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.
参考博客https://stackoverflow.com/questions/14510237/postgresql-with-homebrew-on-mac/16159948,将上面的命令换成:
initdb `brew --prefix`/var/postgres/data -E utf8
即可初始化
STEP_4 重新安装pgadmin4,添加server
重装pgadmin4之后还是没有发现server
但是重新添加server的时候就可以了
以下是添加server的步骤
1、在主页上点击add new server
2、填写名字
应该是随便的,我写的是progres
3、填写连接信息
如下填写。
Username和Password按照软件一开始自己注册的那个账号密码填。
4、点击右下角的save
STEP_4 成功
有server了!